<?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 Tien Young on Medium]]></title>
        <description><![CDATA[Stories by Tien Young on Medium]]></description>
        <link>https://medium.com/@TienYoung?source=rss-2b78c661260a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GKvTXYk4FQ_0MIxs.jpg</url>
            <title>Stories by Tien Young on Medium</title>
            <link>https://medium.com/@TienYoung?source=rss-2b78c661260a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 06:51:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@TienYoung/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[GPU Skinned Fur Instance in Unity]]></title>
            <link>https://medium.com/@TienYoung/gpu-skinned-fur-instance-in-unity-ccc0668b4202?source=rss-2b78c661260a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccc0668b4202</guid>
            <category><![CDATA[hlsl]]></category>
            <category><![CDATA[rendering]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[shaders]]></category>
            <dc:creator><![CDATA[Tien Young]]></dc:creator>
            <pubDate>Tue, 10 Dec 2024 20:22:00 GMT</pubDate>
            <atom:updated>2025-07-08T14:35:30.827Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction:</h3><p>As we all know, the most common method for fur simulation is Shell Based Fur. Simply put, it expands vertices along the normal direction to form stacked shells, then uses a Noise texture as a fur pattern to create the fur shape through hollowing (Clip or Blend). The basic principles and shading methods have been widely discussed online, so we won’t go into detail here. This article introduces a GPU Instance implementation that supports Skinned Mesh in Unity.</p><h3>Background:</h3><p>The most significant problem with Shell-based fur is the exponential increase in the number of faces. A decent animal fur effect on desktop platforms usually uses the Alpha Clip method, requiring at least 100 layers to avoid discontinuities. This is completely unrealistic on mobile platforms, where 8–16 layers are more reasonable. However, this leads to discontinuities, so Alpha Blend must be used, which also avoids breaking Early Z optimization.</p><p>Another issue is how to draw the Shell. The desktop method is to pre-generate with controllable thickness and growth direction. This information and the number of layers are written into VertexColor or UV and drawn in one pass. The mobile approach uses multiple passes. Pre-generation is always an extra step for artists, and even if it can be automated through tools, brushing up additional information like growth direction is troublesome. With fewer layers, the actual effect is not very noticeable, and the file size increases exponentially, so it’s completely unnecessary. Moreover, URP doesn’t support multiple passes by default, so you either need to use multiple materials to implement multiple passes or extend the pipeline with RenderFeature, which is quite cumbersome.</p><h3>Solution:</h3><p>With high faces count, multiple passes, and repeated drawing, this is clearly a case where GPU Instance can be used for optimization. Obtain the mesh of the fur model, write the number of layers into the material block, and <a href="http://walkingfat.com/bump-noise-cloud-3d%e5%99%aa%e7%82%b9gpu-instancing%e5%88%b6%e4%bd%9c%e5%9f%ba%e4%ba%8e%e6%a8%a1%e5%9e%8b%e7%9a%84%e4%bd%93%e7%a7%af%e4%ba%91/">use DrawMeshInstanced to draw</a>. However, Unity’s skinned mesh renderer doesn’t support the GPU Instance. Although there are some workarounds, such as BakeMesh or <a href="https://zhuanlan.zhihu.com/p/36896547">Animation Instancing</a>, they each have their own issues.</p><p><a href="https://unity.com/releases/editor/whats-new/2021.2.0#:~:text=SkinnedMeshRenderer.GetVertexBuffer">Unity added SkinnedMeshRenderer.GetVertexBuffer in 2021.2.0</a>, which perfectly solves the long-standing SkinnedMesh Instance problem. Therefore, the process is to get the VertexBuffer and set it to the Material, draw using DrawProcedual, and SV_InstanceID represents the current layer number.</p><h3>Implementation:</h3><p>This solution uses Unity 2021.2.6f1.</p><p>First, use GetVertexBuffer() to get the vertex Buffer after skinning. Note that only position, normal, and tangent attributes are obtained here. UV and Index need to be obtained from the mesh.</p><blockquote><em>For a mesh to be compatible with a </em><a href="https://docs.unity3d.com/2022.1/Documentation/ScriptReference/SkinnedMeshRenderer.html"><em>SkinnedMeshRenderer</em></a><em>, it must have multiple vertex streams: one for deformed data (positions, normals, tangents), one for static data (colors and texture coordinates), and one for skinning data (blend weights and blend indices).</em></blockquote><p>Set the Buffer to the material.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/0*Ji366pJl30jhWIW-.png" /></figure><p>Then, perform the drawing. For ease of control, I wrote the number of layers into the Material, which must be read here as the number of Instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3ZpsIwe6u_M8m2ip.png" /></figure><p>Finally, for the Shader part, we can only read vertices from the Buffer using SV_VertexID and SV_InstanceID because we&#39;re using Procedural drawing. Note that the Buffer here can only be ByteAddressBuffer, so we must manually parse it.</p><blockquote><em>DirectX 11 does not allow </em><a href="https://docs.unity3d.com/2022.1/Documentation/ScriptReference/GraphicsBuffer.Index.html"><em>Index</em></a><em> or ::Vertex buffers to also be </em><a href="https://docs.unity3d.com/2022.1/Documentation/ScriptReference/GraphicsBuffer.Structured.html"><em>Structured</em></a><em>. For compute shader mesh data access with DirectX 11 compatibility, use </em><a href="https://docs.unity3d.com/2022.1/Documentation/ScriptReference/GraphicsBuffer.Raw.html"><em>Raw</em></a><em>.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/0*PgNQ91AnoIUTIL0X.png" /></figure><p><em>Note: Because we’re using Procedural drawing, we don’t need to enable #pragma multi_compile_instancing. Therefore, UNITY_ANY_INSTANCING_ENABLED is undefined, and there’s no need to use macros from UnityInstancing.</em></p><h3>Result:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e4uIpW0uRuC8DlbFmZETxg.png" /><figcaption><a href="https://github.com/TienYoung/Fur">TienYoung/Fur: Shell based fur unity implementation.</a></figcaption></figure><p>Finally, a single Pass can achieve Shell Fur Shading with any number of layers. There’s no need to pre-generate meshes; the number of layers can be adjusted dynamically, and it supports Skinned Mesh GPU Instance. All of this requires only one DrawCall.</p><h3>Extension:</h3><p>Since we’re getting the vertex buffer after skinning, we can blend <a href="https://www.youtube.com/watch?v=IDRDA-Q8LuY">skinned animations</a>, in addition to the Animation Instance.</p><p><a href="https://docs.unity3d.com/2022.1/Documentation/ScriptReference/SkinnedMeshRenderer.html">2021.2.0</a> not only provides the vertex cache after skinning but also provides the cache from the previous frame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aGwYAcxDTMFLknBk.png" /></figure><p>Based on this, we can simulate the physical effects of fur in CS. Through DrawProceduralIndirect, we can also set the number of layers based on distance, achieving automatic LOD.</p><h3>References:</h3><ul><li><a href="http://walkingfat.com/bump-noise-cloud-3d%e5%99%aa%e7%82%b9gpu-instancing%e5%88%b6%e4%bd%9c%e5%9f%ba%e4%ba%8e%e6%a8%a1%e5%9e%8b%e7%9a%84%e4%bd%93%e7%a7%af%e4%ba%91/">Bump Noise Cloud — 3D噪点+GPU instancing制作基于模型的体积云</a></li><li><a href="https://zhuanlan.zhihu.com/p/36896547">Render- Animation Instancing</a></li><li><a href="https://github.com/cinight/MinimalCompute">cinight/MinimalCompute</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccc0668b4202" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Unity Render Feature]]></title>
            <link>https://medium.com/@TienYoung/exploring-unity-render-feature-347cc07fb0c6?source=rss-2b78c661260a------2</link>
            <guid isPermaLink="false">https://medium.com/p/347cc07fb0c6</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[hlsl]]></category>
            <dc:creator><![CDATA[Tien Young]]></dc:creator>
            <pubDate>Tue, 10 Dec 2024 19:54:53 GMT</pubDate>
            <atom:updated>2024-12-10T19:54:53.475Z</atom:updated>
            <content:encoded><![CDATA[<p>As we all know, URP (Universal Render Pipeline) Shading is single-pass. The default Pass needs to be written under the LightMode of UniversalForward. In previous pipelines, two passes were typically used to render double-sided transparent materials, rendering the back face first and then the front face. But how can we achieve this effect in URP? Modifying the pipeline is certainly possible, and URP’s logic is quite simple. However, changing the pipeline specifically for this special effect reduces flexibility and is not a good solution. This is where we introduce a very cool feature in URP — RenderFeature.</p><p>RenderFeature allows flexible insertion of command buffers at various stages of rendering. The insertion point is determined by RenderPassEvent, as shown in the following image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6eo4CGOfOCxBPHMw.png" /></figure><p>It’s incredibly detailed, as you can see.</p><p>I’ll use RenderFeature to implement a double-sided transparent material by inserting a Pass.</p><p>First, prepare a Shader. I directly copied Lit.shader here. Then, add a Pass at the beginning to render the back face. The shading for both the back and front faces is the same, so I copied UniversalForward directly and set Culling to Front. Finally, define your own LightMode; I wrote it as BackFace here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l0sWGQKWT_Rxp0X2.png" /></figure><p>The URP source code comments are quite good, making it easy to understand the rendering logic.</p><p>Next, create a RenderFeature. In the Project, go to Create -&gt; Rendering -&gt; Universal Render Pipeline -&gt; Renderer Feature. There’s already a template here. We need to pay attention to the Pass inside. The Execute method is where you write your command buffer. I’ll take another shortcut and copy the code from DrawObjectPass. This is the Pass for rendering Universal Forward. The logic for back and front faces is the same; only the Pass used differs, so change the ShaderTagId to “BackFace.” Since the back face only applies to transparent cases, set the RenderQueueRange to transparent. Set the insertion point RenderPassEvent to BeforeRendingTransparents to ensure it renders before transparent objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1fAL_Kn1slK4fFzS.png" /></figure><p>This is the entire logic.</p><p>Find your Forward Renderer or create a new one. Add the RenderFeature you just wrote to it. Then, find the Render Pipeline Asset (in Project Setting -&gt; Graphics), and add the Renderer you just created to the RendererList. Finally, select the renderer with the render feature for your camera, and you’ll be able to see the effect in the Game window. Currently, it seems RenderFeature only works in the Game view. By setting Default in the URP Asset, you can see the same effect in the Scene View as in the Game View.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/0*mcQuXc3ZP1nv9fOi.png" /><figcaption><em>Set or create a Renderer</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/0*dB1S0zghk4PhkzBt.png" /><figcaption><em>Add Renderer to Pipeline Asset</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/0*OPF0ORotayuH918Q.png" /><figcaption><em>Camera select Renderer</em></figcaption></figure><p>Below is a comparison of the effects. On the left is a forced two-sided rendering of transparency, and on the right is the multi-pass transparency effect achieved through the above method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JdPobeua0U1GVcJe.png" /><figcaption><em>Source: </em><a href="https://github.com/candycat1992/Unity_Shaders_Book"><em>Unity Shader入门精要 by Candycat</em></a></figcaption></figure><p>The texture is from Lele Feng’s “Unity Shader Essentials.” You can see that on the left, because the front and back faces are rendered in one Pass, the order is not distinguished, resulting in chaotic front-back relationships. On the right, the rendering order of the front and back faces is separated, resulting in the correct display effect.</p><p>The function of the Render Feature is essentially to give TAs and graphics programmers more flexibility in extending URP by inserting Passes. Although URP is somewhat rudimentary, its code logic and comments are quite clear. It’s a good resource for beginners who want to learn about pipeline rendering. URP doesn’t seem very popular, even though it’s been out for so long. Some people see the comparison with built-in RP, notice that many features are missing, and think it’s lightweight and unwilling to use it. In fact, through RenderFeature and code modifications, URP can absolutely achieve more and better effects than built-in RP. Don’t wait for the official implementation of features; Unity is getting further and further away on the AAA path, which I would call sick.</p><p>Finally, let me show another clever use of RenderFeature. This one is used to display the depth texture on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EkzRdFj4LkQLsywX.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/0*p_k_dnv84z61FjEO.png" /></figure><p>This is a common full-screen Blit similar to post-processing. The Shader is simpler; you need to put the relevant Buffer.</p><p>Then, create a renderer for the corresponding RenderFeature and add it to the pipeline. This way, you can switch renderers in the camera to display different buffers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*x-Y2VM6SQ-3UAnaC.png" /><figcaption><em>Depth</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/0*BUNjxBMq9492xvU4.png" /><figcaption><em>Depth slices</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/0*UtEwZahHJLEvfcWo.png" /><figcaption><em>World Position from Depth</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/0*HnIleYlzj5e9dVMC.png" /><figcaption><em>Opaque</em></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=347cc07fb0c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>