<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Samsy on Medium]]></title>
        <description><![CDATA[Stories by Samsy on Medium]]></description>
        <link>https://medium.com/@Samsy?source=rss-cb643122d628------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*WLx4dCwG6yXnhM-o.jpeg</url>
            <title>Stories by Samsy on Medium</title>
            <link>https://medium.com/@Samsy?source=rss-cb643122d628------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 22:15:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Samsy/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Detecting Apple A10 ( Iphone 7 ) to A11 (Iphone 8 and ++)]]></title>
            <link>https://medium.com/@Samsy/detecting-apple-a10-iphone-7-to-a11-iphone-8-and-b019b8f0eb87?source=rss-cb643122d628------2</link>
            <guid isPermaLink="false">https://medium.com/p/b019b8f0eb87</guid>
            <category><![CDATA[iphone]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webgl]]></category>
            <dc:creator><![CDATA[Samsy]]></dc:creator>
            <pubDate>Tue, 29 Oct 2019 12:31:07 GMT</pubDate>
            <atom:updated>2019-10-29T13:39:40.598Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ilayD7inuotT1xf2t7QaZA.jpeg" /></figure><p>Device detection has always been mandatory in order to build rich compatible and adaptable web-experiences.</p><h3>Before:</h3><p>Some are easy to detect: iPhoneX, for example, has a <em>window.devicePixelRatio</em> of <strong>3.0</strong>. However, some are really tricky because they are the same size.</p><p>Let’s take the following example: iPhone 6–7 and 8 are : 375px X 667px.</p><p>The one way to differentiate them is using the WebGL trick of reading the GPU name, and because they are different, you could tell:</p><p>If the GPU name is: Apple A9 =&gt; SE / 6S</p><p>If the GPU name is: Apple A10 =&gt; 7</p><p>If the GPU name is: Apple A11 =&gt; 8</p><p>etc..</p><p>Reference can be found here: <a href="https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_debug_renderer_info">https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_debug_renderer_info</a></p><h3>Now:</h3><p>Recently, from IOS 12.2, Apple decided to obfuscate this information and would return a generic <strong>‘Apple GPU’</strong> (<a href="https://51degrees.com/blog/apple-ios-122-degrades-device-detection-accuracy">https://51degrees.com/blog/apple-ios-122-degrades-device-detection-accuracy</a>)</p><p>I’ve tried to find a way to differentiate them without success for a few hours before writing a WebGL GLSL test as follows:</p><p>1 ) Write a small value ( between 0 and 1 ) with a lot of decimals into a float variable like :</p><p>0.31622776601683794</p><p>2 ) Encode it into a RGBA pixel</p><p>3 ) Write it into a RGBA texture</p><p>4 ) Read back this value using readPixels</p><p><strong>This is where the magic happens</strong>: iPhone 7 and iPhone 8 GPUs don’t handle the same floating point precision, and therefore they return different results !</p><p>Example :</p><p><a href="https://github.com/Samsy/appleGPUDetection/blob/master/index.js">https://github.com/Samsy/appleGPUDetection/blob/master/index.js</a></p><p>This example is using THREE.js for a fast demonstration, but can be converted to a lighter WebGL test.</p><p>UPDATE : <br>This is clearly a ridiculous way of detecting hardware. This should not be that hard.</p><p>Many thanks</p><p><a href="http://samsy.ninja/">Samsy / Creative Technologist / WebGL / 3D Dev</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b019b8f0eb87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Legend of IceCoon case study / Advanced webGL - First Part]]></title>
            <link>https://medium.com/@Samsy/the-legend-of-icecoon-case-study-advanced-webgl-first-part-185742e82429?source=rss-cb643122d628------2</link>
            <guid isPermaLink="false">https://medium.com/p/185742e82429</guid>
            <category><![CDATA[webgl]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-graphics]]></category>
            <category><![CDATA[threejs]]></category>
            <category><![CDATA[shaders]]></category>
            <dc:creator><![CDATA[Samsy]]></dc:creator>
            <pubDate>Mon, 26 Dec 2016 13:53:46 GMT</pubDate>
            <atom:updated>2017-02-02T22:39:13.352Z</atom:updated>
            <content:encoded><![CDATA[<p>For the end of the year, I enjoyed building a little THREE.JS game for this year’s Christmas Experiments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rhQy7AsSFjbDR1INztlPpg.jpeg" /></figure><p><a href="http://christmasexperiments.com/2016/20/the-legend-of-the-icecoon/">http://christmasexperiments.com/2016/20/the-legend-of-the-icecoon/</a></p><p>Christmas experiments have been initiated by David Ronai in 2012, with the goal to deliver great experiments and highlight top web creatives as well as newcomers. <br>I used a lot of advanced techniques I’d like to share with everyone.<br>To let everyone know also, this is my first blog post ever !</p><p>I’ll try to be descriptive, please do not hesitate to ask any questions if there are any blurry parts.<br>If I’m wrong about a concept I’ll be more than glad to hear from you :)</p><p>( Thank you <a href="https://medium.com/u/51dbd11653c4">Alvin</a> for correcting my french-glish )<br>#EXCUSEMYFRENCH</p><h3>The technical self-brief</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*1SQshvenWwJ5qPlasGwpuQ.gif" /><figcaption>Video Reference I found on the internet from a 3D render</figcaption></figure><p><strong>Constructing an infinite diamond tunnel</strong> you dive into, <strong>with lights, env and normal map / bloom postprocessing</strong> / the <strong>ability to switch graphics and travel through worlds + cross fade transitions, “</strong>trying” to keep it <strong>60 fps on a retina display</strong>, <strong>even on mobile</strong>.</p><p>It sounds like a little challenge to me, I’ll go step by step.</p><p>And I’ll start with…..</p><p><strong>Constructing an infinite tunnel</strong></p><p>There’s no secret about the position distribution of the tunnel, it is based on a TubeGeometry. <a href="https://threejs.org/docs/#Reference/Geometries/TubeBufferGeometry">https://threejs.org/docs/#Reference/Geometries/TubeBufferGeometry</a> <br>The idea is to create a tube geometry from a curve and extract the position of the vertices, place a rotated mesh on each of them, sit and look.</p><p>For the camera movement, this has been done before by the excellent <a href="http://www.lab4games.net/zz85/blog">zz85</a></p><p><a href="https://threejs.org/examples/#webgl_geometry_extrude_splines">https://threejs.org/examples/#webgl_geometry_extrude_splines</a></p><p>No sorcery there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*Bn2LDmh1Oq7xFdpvCX_1OQ.gif" /></figure><p>The problem is, rendering like this will cost you a lot of draw calls ( number of mesh visible = number of draw calls ), and draw calls is one of the bottlenecks in graphics rendering.</p><p>And you would want to save some processing and frame time to render cool fullscreen post processing effects and heavy materials with your cubes.</p><p><strong>Geometry Instancing</strong></p><p>To reduce the draw call count, we we’ll use a <strong>Geometry Instance</strong>.<br>This is not well documented on THREE.JS but you can find an example here.<br><a href="https://threejs.org/examples/#webgl_interactive_instances_gpu">https://threejs.org/examples/#webgl_interactive_instances_gpu</a></p><p>The idea is to render multiple copies of the same primitive ( or geometry ) in a scene at once, using one single draw call. Geometry Instancing can help us to do that. In our case, render hundreds of <strong>instances</strong> of the same geometry <strong>in a single mesh.</strong></p><p>An instanced mesh got some attributes shared across all the geometry, and their own InstancedAttributes which are specific to the current instance.</p><p><a href="https://github.com/mrdoob/three.js/blob/master/src/core/BufferAttribute.js">Attribute</a>s<br>Each instance of the single mesh are all sharing the same set of attributes like, position ( describes the structure of the geometry ) , normals, uvs etc...<br>Nothing different than the usual buffers here.</p><p><a href="https://github.com/mrdoob/three.js/blob/master/src/core/InstancedBufferAttribute.js">InstancedAttribute</a>s<br>And you can have individuals proper attributes like offset ( to displace the geometry in space ), scale, color, ID, so each instance can have a different offset displacement, unique look etc..</p><p>In this case, each cube needs to be positioned on each of the tube vertices, using an InstancedBufferAttribute that describes the offset of each cubes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vfiUgCHodXG1bxwKpi0Euw.png" /></figure><p>And the usage in-shader.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*CowkjHh7RAhwnC7JCCtX7g.png" /></figure><p><em>An example of Instanced geometries + GPGPU</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ny7ua03cpFXL2KobQNBg3w.png" /></figure><p>Now we can render the whole tunnel in a single draw call.</p><p>In my case there are 5320 instances ( number of vertices on the tube geometry ) * 12 vertices ( 60 indexed vertices ) = 63840 vertices and as many call to the vertex shader.</p><p>I asked myself if I could render only the visible cubes in front of the camera, to reduce the number of instances and not having to renderer all the vertices of the geometry on each frame and reduce the amount of vertex-shader calls.</p><p>So I’d want only 1024 mesh in my instanced geometry instead of 5320.</p><p><strong>Geometry Texture</strong></p><p>As a performance geek, I used a solution that allow me to render what is only visible in front of me in the tunnel using what we call a Geometry Texture.</p><p>A geometry texture is a texture that describes one or multiple components of geometry ( vertex positions, uvs ).</p><p>Using textures and RGBA components to write data that are not supposed to be displayed on a screen is a well-known technic.</p><blockquote>The GPGPU ( General Purpose Graphical Processing Unit ) is a good example of what we can do with Data Textures. You can read more about on the excellent blog post of <a href="https://medium.com/u/2f6d7451b3b">Nicolas Barradeau</a>. <a href="http://barradeau.com/blog/?p=621">http://barradeau.com/blog/?p=621</a></blockquote><p>The idea is to transpose the vertices positions of the tube geometry into a <a href="https://github.com/mrdoob/three.js/blob/master/src/textures/DataTexture.js">Data Texture</a> using the RGB component of a texture.</p><p>X = R <br>Y = G <br>Z = B</p><p>In my case, I need to store 5320 positions ( number of positions of the tube geometry ).</p><p>To support older GPUs ( not sure it is still the case today, probably not ), to reduce GPU memory consumption, and texture padding in gpu ( you can find some reading and discussion about this )….<br>… I’ll prefer to store the data in a power of 2 texture.</p><p><em>Disclaimer : I’ll be glad to hear about this if someone knows more..</em></p><p>We’ll determine the lowest size we can use to store theses positions.</p><p>128 * 128 = 16384</p><p>64 * 64 = 4096</p><p>128 * 64 = 8192</p><p>16384 is too much, 4096 is too low, 8192 is ok !</p><p>And because we are lucky, all the vertices of the geometry are generated inline as a Slinky…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*I1IaY7oicoa0qWSL0_Q7hw.jpeg" /></figure><p>…every positions will be stored as a single line in the dataTexture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F0D4NYFS5mwm7pGWrn9PrQ.png" /></figure><p>There will be a lot of empty pixels ( 8192 - 5320 = 2872) we’ll just set them to zero because we wont use them anyway.</p><p>This array contains the data of our DataTexture.<br><a href="https://github.com/mrdoob/three.js/blob/master/src/textures/DataTexture.js">https://github.com/mrdoob/three.js/blob/master/src/textures/DataTexture.js</a></p><p>Once we got our geometry texture that describes the whole tube geometry, we’ll send this texture as a sampler2D in the shader.</p><p>Here how a dataTexture looks :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*4jNOvRlBF0B9NQqFEsZkfw.gif" /></figure><p><em>PS : You can have a look at the excellent FBOHelper and inspector made by </em><a href="https://medium.com/u/7d80d30f321"><em>Jaume Sanchez Elias</em></a><em><br></em><a href="https://github.com/spite/THREE.FBOHelper"><em>https://github.com/spite/THREE.FBOHelper</em></a></p><p>And how ours looks like :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h1iG3coFeiUR4BP5I-4PQw.jpeg" /></figure><p><strong>Reading the Geometry Texture in shader</strong></p><p>We want each instances to be unique, and let them know they are unique.<br>For that we’ll just set an unique ID to each instances in an <a href="https://github.com/mrdoob/three.js/blob/master/src/core/InstancedBufferAttribute.js">InstancedAttribute</a>. 0, 1, 2 …. , 1022, 1023.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y3VAmRfpJHyHHfnL7KW3Ag.png" /></figure><p>So in the shader, each instance has now a unique ID that we can now access in this attribute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*xc0om5XrNGjcGJ08WGFACg.png" /></figure><p>We’ll need to send the DataTexture</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*s2GIMELIo82xQ3WsFq9Gjw.png" /></figure><p>We’ll need to set the data texture size as a uniform. [128, 64]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*3KvALastt9ErT3bsZgEd_Q.png" /></figure><p>We’ll need the vertices length that has been transposed into the texture [ 5320 ].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*HQWIBUV9ewXXPwSw8qnRyg.png" /></figure><p>The camera is moving, and looping inside the tube.<br><em>As a reminder : </em><br><a href="https://threejs.org/examples/#webgl_geometry_extrude_splines"><em>https://threejs.org/examples/#webgl_geometry_extrude_splines</em><br></a>The shader needs to know whats the current progression of the camera inside the tube ( beginning is 0, end is 1 ).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*mGiS7nOOrlxHA-D77Rl-NQ.png" /></figure><p>The idea, is to displace the instances unique ID with the current progression of the camera in the tunnel.</p><p>Transform the 1 dimension displacedID coordinate into a 2D normalized row, col, based on the texture dimension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*SxVD3yNjsLo8bf4_egcgWA.png" /></figure><p>Then read the dataTexture from this coordinate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dC92GID1YbCyAJy0WmoQRg.png" /></figure><p>To show you how it works, here’s what I can see if I display the uvToRead as a color. <br>We can clearly see the red channel / X uv coordinate looping from 0 to 1, and the shade of the green channel / Y uv coordinate incrementing on the progression.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*zOTzgLNSGuxWnPMGIBZ1Hw.gif" /></figure><p>Because… The X value of the uvToRead is looping from 0 to 1 on a 128 indices basis, and every 128 index, the Y value is incrementing a bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*egPqLHUEEUk9aCCbXRfzrw.jpeg" /></figure><p>Here’s a capture of how it looks when the progression loops !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J0dS1JQUup8ZsHOfrz_5KA.png" /></figure><p>I now have a geometry of 1024 instances that morphs and changes position on its own, one draw call, with a single material.<br>The only and single thing left to make it work now is to update the currentLoopDisplacement value from 0 to 1 according to the camera position.<br>The mesh is completely independent, theres no attributes update / cpu workload / no data or textures upload to the GPU = HUGE WIN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*WIAHJ6Ao5FprzI0pZCIknw.gif" /></figure><p>This is incredibly performant, and runs really smoothly on a lot of computers / GPU / Mobile. Even a mac book air 13&#39;’ with a cheap chipset / iPhone5. I just saved some processing and can concentrates on the look and feel on the experience !</p><p><strong>To be continued… ( Post processing + cross fade ).</strong></p><p>For the time being you can visit my portfolio :</p><p><a href="http://samsy.ninja/">http://samsy.ninja</a></p><p>Or / And / Follow me on twitter :)</p><p><a href="https://twitter.com/Samsyyyy">https://twitter.com/Samsyyyy</a></p><p>I’m also free-lancer working on webGL projects for production studios or other independents. But can look for legendaries full-timer positions.</p><p>And big kudos for my bro, favorite designer, and one of my best friends :</p><p><a href="http://stevenmengin.com/">http://stevenmengin.com/</a></p><p><a href="https://twitter.com/steven_mengin">https://twitter.com/steven_mengin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=185742e82429" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>