<?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 José Pizarro on Medium]]></title>
        <description><![CDATA[Stories by José Pizarro on Medium]]></description>
        <link>https://medium.com/@jmprocco?source=rss-2b3b6150867------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*4ZL6tYz4NC53zjpMZjFmmA.png</url>
            <title>Stories by José Pizarro on Medium</title>
            <link>https://medium.com/@jmprocco?source=rss-2b3b6150867------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 12:53:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jmprocco/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[Dynamic flowing foam in Unity]]></title>
            <link>https://medium.com/@jmprocco/dynamic-flowing-foam-in-unity-11811775043e?source=rss-2b3b6150867------2</link>
            <guid isPermaLink="false">https://medium.com/p/11811775043e</guid>
            <category><![CDATA[techart]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[José Pizarro]]></dc:creator>
            <pubDate>Mon, 27 Sep 2021 00:09:05 GMT</pubDate>
            <atom:updated>2021-11-29T15:40:52.195Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*5VJ_QAfwesMTTUCfmfEO0w.gif" /></figure><p>In this article, I’ll explain how to achieve a dynamic flowing foam in Unity. This article is not a step-by-step tutorial but more of a general guideline of how to achieve the effect. I’ll be using URP, but this technique can be extrapolated to any rendering pipeline. This effect is based on <a href="https://dl.acm.org/doi/10.1145/3214745.3214820">this awesome SIGGRAPH presentation</a>. So check it out if you want to know more about this it. You Can find the source files at the end of the article.</p><h3>Setup</h3><p>Assuming that you already have a URP project, add a plane and a bunch of mesh renderers into the scene.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*ZuKs8EbXQfwd9DhvIo69nQ.png" /></figure><h3>Dynamic Foam Renderer Feature</h3><p>First, we need to create a Renderer Feature called “DynamicFoamRendererFeature”. A Rendererfeature allows us to extend the rendering pipeline. They are very flexible and will enable us to decouple the rendering logic from a particular scene. We will set the renderPassEvent as BeforeRenderingOpaques so our texture could be sampled by opaques objects as well.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6a9d631997ecbc632082257a4a7a450/href">https://medium.com/media/f6a9d631997ecbc632082257a4a7a450/href</a></iframe><p>The first thing that we need is to store the depth difference between the plane and the objects that the plane intersects. We can achieve this by creating a custom <strong>shader pass </strong>that will compute the depth difference and render it into a custom render target.</p><p>In the code we do this by getting a render texture and setting it as the render target calling ConfigureTarget. Note that the render target identifier and the render texture identifier must be the same for them to be linked. We also need to release our render texture inside the FrameCleanup method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16f2952ee59bb6ae2488e5d4706779ae/href">https://medium.com/media/16f2952ee59bb6ae2488e5d4706779ae/href</a></iframe><p>Then we need to execute the render feature. Here is where we will render our custom shader pass where the depth difference is supposed to be rendered. We can achieve that by creating a DrawSettings and passing our shader pass identifier to it. Then if we call DrawRenderers passing our draw settings we will render all the objects that have our custom shader pass on its shader.</p><p>Finally, we set our global texture passing our render target identifier to debug it later.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c927da6e832835d5a04fb1e9d2536b0/href">https://medium.com/media/5c927da6e832835d5a04fb1e9d2536b0/href</a></iframe><h3>Depth difference Shader Pass</h3><p>Here is where the magic happens. We need to map the plane into the screen using its UVs as clip position. This way, we can effectively output its fragment into our render target (Remember that we are using the camera render target descriptor in our custom render target). Still, we also need to compute the vertex clip position to calculate its depth relative to the camera. The lightmode tag <strong>must</strong> be the same as the ShaderTagId set on our custom render feature.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bf9a8bb1db436db9ea9aaeeb982d805/href">https://medium.com/media/3bf9a8bb1db436db9ea9aaeeb982d805/href</a></iframe><p>Then we can sample our foam texture inside the forward pass of our shader.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d7d73e7b0e21922cfb79cd967c9d212/href">https://medium.com/media/5d7d73e7b0e21922cfb79cd967c9d212/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*r9U-oavK0kjNmEnZE5X3rQ.png" /></figure><h3>Flow</h3><p>The next step is to make the foam “flow” We can achieve this by two additional render textures, one to store the previous state of the flow and the second to store the current state. I’ll use a compute shader to apply the flow but this could also be performed on a fragment shader.</p><ul><li>Sample the current depth from the DepthDifference texture</li><li>Create a flow vector proportional to the texture size (Here I hardcoded (1,0) as the flow direction for simplicity)</li><li>Sample the previous foam from _DepthFoam_Read</li><li>Set the current foam in _DephFoam_Write equals to the current depth plus the displaced foam.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b599752f4504723247398c3fb090cd95/href">https://medium.com/media/b599752f4504723247398c3fb090cd95/href</a></iframe><p>Then we need to initialize our read and write textures. We can initialize them inside the <strong>Configure</strong> method. (Note that we will need to manually dispose of these textures once we don’t need them anymore)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b25b4b55048b3e70e3b81ece6b047dae/href">https://medium.com/media/b25b4b55048b3e70e3b81ece6b047dae/href</a></iframe><p>After that, we need to pass these textures to our compute shader, execute our kernel, and then swap them at the end of the frame. We can do this by calling <strong>SwapFoamTextures</strong> inside the <strong>FrameCleanup</strong> method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9c9718f3ef5fdfd8501a2f8fcfbc57f/href">https://medium.com/media/d9c9718f3ef5fdfd8501a2f8fcfbc57f/href</a></iframe><p>Finally, we need to set up our render pass in our renderer data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*SWZrTdZ0-ttUbD6t_N06MQ.png" /></figure><p>The effect is mostly done. All that is left is to make it look pretty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*TAJ0aCc0KieBhRd9FDSidw.gif" /></figure><p>We can add a nice distortion using a distortion map</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*-VRy8wLyea4mR_6GwqiROQ.gif" /></figure><p>Now it’s looking more interesting but it can looks way better if we apply some blur on it. I just lazily made some adjustments to <a href="https://www.ronja-tutorials.com/post/023-postprocessing-blur/">Ronja’s Blur Postprocessing Effect tutorial</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*q77x4DlGdD9Psp-kGjfi4A.gif" /></figure><p>That’s all! I hope this to be useful to you c:</p><h3>Source Code</h3><p><a href="https://github.com/JoseMiguelPizarro/DynamicFlowingFoam">https://github.com/JoseMiguelPizarro/DynamicFlowingFoam</a></p><h3>References</h3><p><a href="https://dl.acm.org/doi/10.1145/3214745.3214820">The Technical Art of Sea of Thieves</a></p><p><a href="https://www.ronja-tutorials.com/post/023-postprocessing-blur/#gaussian-blur">Blur Postprocessing Effect (Box and Gauss)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11811775043e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automatize your customs Unity editor tools GUI using assemblies and the Strategy pattern]]></title>
            <link>https://medium.com/@jmprocco/automatize-your-customs-unity-editor-tools-gui-using-assemblies-and-the-strategy-pattern-9774d51024df?source=rss-2b3b6150867------2</link>
            <guid isPermaLink="false">https://medium.com/p/9774d51024df</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[csharp]]></category>
            <dc:creator><![CDATA[José Pizarro]]></dc:creator>
            <pubDate>Sat, 31 Aug 2019 17:58:40 GMT</pubDate>
            <atom:updated>2019-09-01T01:28:42.209Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pu1HpvLS_Zv_aBLRFawebA.png" /><figcaption>Steelworks at Königshütte in the 1870s in Chorzow, Poland. Artwork by Adolph von Menzel .</figcaption></figure><p>Let’s put ourselves in the next scenario: Suppose we are creating a new fancy tool for editing meshes in the scene view so we create a new monobehaviour called LevelMesh<strong> </strong>and a custom editor class called LevelMeshEditor<strong>. </strong>The first functionality that we need is a selection tool so we create a new GUIContent with its own icon like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15d790192773fa25aa6ad2b9f02b1fcc/href">https://medium.com/media/15d790192773fa25aa6ad2b9f02b1fcc/href</a></iframe><p>Then we are going to create a GUIContent[]array to display it later as a selection grid.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee56bee64b678092d9d3d6df6be2aea7/href">https://medium.com/media/ee56bee64b678092d9d3d6df6be2aea7/href</a></iframe><p>So far so good, now we need a way to display our buttons in the scene, to do that we are going to create a new method DrawToolBar() to render our toolbar an then call it inside OnSceneGUI(). Also we need to create a variable to track our current selected tool, we are going to call it selectedTool.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/876c417d343d51f482c360132f963065/href">https://medium.com/media/876c417d343d51f482c360132f963065/href</a></iframe><p>If you go back to the scene view you should have something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*_cz6ZDtKf4vxACVuGkXVHg.png" /></figure><p>Finally we need our tool to have some functionality. To do so we create a new method called DoAction() which will resolve our current selected tool. And then call our method inside OnSceneGUI().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/649b1c9550568dda6efb2e18e94e633e/href">https://medium.com/media/649b1c9550568dda6efb2e18e94e633e/href</a></iframe><p>Now we need a resize tool, so we repeat the process again ended with something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4a168189ef598dc1e9f3f4fe396fc4e/href">https://medium.com/media/c4a168189ef598dc1e9f3f4fe396fc4e/href</a></iframe><p>As you can see there is a lot of boilerplate code in here and as your editor tool grows in complexity this could easily end in a giant monolithic unsustainable piece of code.</p><p><strong>DESIGN PATTERNS TO THE RESCUE!</strong></p><p>To solve this problem we are going to use the Strategy pattern. Strategy pattern is a behavioral design pattern that consists in encapsulate a family of algorithms and interchange or select them at runtime. First, we are going to create an abstract class which will be in charge of encapsulate all the data needed for a tool to work. Every tool need three basic things to work: A context (Which is the current state of our LevelMeshEditor), a functionality, and an icon to be displayed. Every tool needs to implement an Act(LevelMeshEditor editor, Event current) method, the Event parameter will be used for handling inputs if you need it. Notice how the GUIContent is being initialized in the constructor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13f493bfc9553db7a9749f6a7d159504/href">https://medium.com/media/13f493bfc9553db7a9749f6a7d159504/href</a></iframe><p>Then we have to implement that class for every tool that we want to add:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3c58e5fd4a54a5a5fa55c1d0c9a772a/href">https://medium.com/media/e3c58e5fd4a54a5a5fa55c1d0c9a772a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9397191c04b60c590a0820bb9136f85/href">https://medium.com/media/c9397191c04b60c590a0820bb9136f85/href</a></iframe><p>Now we need a way to wrap up all our tools and provide them to our editor. This is where we are going to use C# assemblies to get all our classes that extends from LevelMeshTool. We are going to create a static class called LevelMeshToolProvider which will be in charge of inject our tools wherever we need them. First we need a way to access to every type inside our app domain for later filtering only those types that inherit from LevelMeshTool.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18c4ac857b3cffb3e73e7af612b51619/href">https://medium.com/media/18c4ac857b3cffb3e73e7af612b51619/href</a></iframe><p>Then we are going to create a List&lt;LevelMeshTool&gt; to store all our tool’s instances. And finally we need to write a private constructor for our provider to instantiate all our tools, a private constructor for a static class runs only the first time the class is referenced so it is a perfect place to initialize our list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d15a5b2bf3cae0e9b1abd5c27fa01b6a/href">https://medium.com/media/d15a5b2bf3cae0e9b1abd5c27fa01b6a/href</a></iframe><p>Finally we need to implement this in LevelMeshEditor. First, we need to create a reference to our current active tool. And then use our selectedTool as an index to access to our active tool. Lastly we initialize a reference to all our tools in OnEnable()</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f38bc91f38d1b49be190e1a56876222/href">https://medium.com/media/1f38bc91f38d1b49be190e1a56876222/href</a></iframe><p>The last thing that left to tie up is resolve the active tool’s action. That’s so simple as call our current active tool’s Act() method inside OnSceneGUI().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d56d03132abe0ea74af4fd890f7c90f1/href">https://medium.com/media/d56d03132abe0ea74af4fd890f7c90f1/href</a></iframe><p>If you go back to the editor everything is working as it should be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*RjhR1Iv6EA7KIeCFadzfOw.png" /></figure><p>You can add even more functionalities to our LevelMeshTool for example you could create a custom DrawHandle method for each tool or a custom SceneGUI it’s all up to you.</p><p>That’s all folks, I hope you find this useful.</p><p><strong>Example repository:</strong></p><p><a href="https://github.com/JoseMiguelPizarro/ArticleExample01">https://github.com/JoseMiguelPizarro/ArticleExample01</a></p><p><strong>Shameless plug: </strong>follow me on Twitter <a href="https://twitter.com/JoseHojaverde">https://twitter.com/JoseHojaverde</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9774d51024df" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>