<?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 Michael Sanders on Medium]]></title>
        <description><![CDATA[Stories by Michael Sanders on Medium]]></description>
        <link>https://medium.com/@pixelcurio?source=rss-9bb6c5ba1e6d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VEF0bSUGniRXuZ8b-F-Qzg.jpeg</url>
            <title>Stories by Michael Sanders on Medium</title>
            <link>https://medium.com/@pixelcurio?source=rss-9bb6c5ba1e6d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 20:52:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pixelcurio/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[Building Unity3D Apps with AWS CodePipeline]]></title>
            <link>https://medium.com/@pixelcurio/building-unity3d-apps-with-aws-codepipeline-2e5fc164d197?source=rss-9bb6c5ba1e6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e5fc164d197</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[codepipeline]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[ci]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Michael Sanders]]></dc:creator>
            <pubDate>Sun, 07 Nov 2021 01:59:44 GMT</pubDate>
            <atom:updated>2021-11-07T01:59:44.430Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-AhkZFGJYyWnNFuaA4fIug.png" /></figure><p>Let’s get right into it. You want to build Unity3D apps using AWS CodePipeline but can’t find any resources on how to do so. Let’s fix that.</p><p>In this article we will create an AWS CodePipeline that pulls from a Bitbucket repo, builds a Unity app inside a docker container, and stores the resulting app in an S3 bucket.</p><h3>Things You Will Need</h3><ul><li>An AWS account</li><li>A Unity Pro or Enterprise account</li><li>A functional understanding of Git, Docker, and AWS CodePipeline</li></ul><h3>Pre-Steps</h3><p>Let’s take care of a few things now to make the actual pipeline creation process smoother.</p><h4>Buildspec.yml</h4><p>First let’s add a buildspec.yml file to the root of our Unity project. This buildspec file will tell AWS CodePipeline how to build our project. This is the secret sauce of this article and probably the most important takeaway. This buildspec file is meant to be used with a docker image from <a href="https://game.ci/">Game.ci</a>, which we’ll get into more later.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af779a28bf7d44b8bcd8e3e0f18532c0/href">https://medium.com/media/af779a28bf7d44b8bcd8e3e0f18532c0/href</a></iframe><p>This is a basic buildspec file for building a Win64 executable. If that is the target architecture for your app then all you should need to change is a couple variables at the top. Set your BUILD_OUTPUT_NAME to the name of your application and change the version numbers (MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION) to match the semantic version of your build. In the future, I’d like to automate this to pull the version number from the Unity project, but for now, we set it manually.</p><blockquote>If you haven’t had a chance to look into semantic versioning, I highly recommend it. The full details of the versioning system are detailed here: <a href="https://semver.org/">https://semver.org/</a></blockquote><p>Some of the environment variables in our buildspec file such as UNITY_EMAIL and UNITY_PASSWORD we will set in our build pipeline.</p><p>We include a command to pull in git submodules but it’s very important to note that your submodules’ urls must be set as https as AWS can’t pull git repos over SSH. Here’s an example of what your .gitmodules file should look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cbc56be3ad8ee5d1882fe9e4da21dd6/href">https://medium.com/media/3cbc56be3ad8ee5d1882fe9e4da21dd6/href</a></iframe><p>Finally, the cache: portion of the build spec file can be removed, but this will increase your build times substantially and because costs for CodePipeline are usage based, saving time is saving money.</p><h4>Dockerhub Account Secrets</h4><p>Head over to the AWS Secrets Manager and create a new secret. We’re going to be storing our login details for Dockerhub.</p><blockquote>It should be noted, this step isn’t strictly necessary, however, if we don’t use a personal login for pulling containers from Dockerhub our pipeline will frequently fail due to being rate limited. You can find more details here: <a href="https://aws.amazon.com/blogs/containers/advice-for-customers-dealing-with-docker-hub-rate-limits-and-a-coming-soon-announcement/">https://aws.amazon.com/blogs/containers/advice-for-customers-dealing-with-docker-hub-rate-limits-and-a-coming-soon-announcement/</a></blockquote><p>At the “Store a new secret” screen, select the “Other types of secrets” secret type. We’re going to store two key/value pairs, a username and password. Use the username and password for your Dockerhub account. Your page should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9j9pSyTYWLTtx3IjrGVMjw.png" /><figcaption>Example of storing a raw text password in AWS Secrets Manager.</figcaption></figure><p>Click Next, give your secret a nifty name, and click Next two more times. (We don’t care about setting up automatic rotation.) Finally you will be able to click “Store” and your password is created. The last step is to grab the ARN for this secret. It should look something like:<br><strong><em>arn:aws:secretsmanager:us-west-2:129537593583:secret:Dockerhub-SlYuTO<br></em></strong>Save this ARN for later.</p><h3>The Pipeline</h3><p>Let’s create our Pipeline. Head over to CodePipeline and create a new pipeline in you preferred region. Give your pipeline a name and leave the rest set to default values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*Q0ibHEZZcgB19ANqobNQqA.png" /><figcaption>Basic CodePipeline settings.</figcaption></figure><h3>Source</h3><p>Select the source provider you utilize. For the sake of this tutorial we’re going to use Bitbucket as an opportunity to talk through some additional steps needed to allow our pipeline to make git calls back to our repo to pull submodules.</p><blockquote>We’re going to skip the steps necessary to connect Bitbucket to your AWS account. However, if you need details on how to setup that connection, you can follow this official AWS blog post: <a href="https://aws.amazon.com/blogs/devops/using-aws-codepipeline-and-aws-codestar-connections-to-deploy-from-bitbucket/">https://aws.amazon.com/blogs/devops/using-aws-codepipeline-and-aws-codestar-connections-to-deploy-from-bitbucket/</a></blockquote><p>Choose your repository and branch. For the Output artifact format, select “Full clone”. This way when your source is cloned by the pipeline it will include the .git folder, allowing our build step to perform git commands. In our case, this is necessary so we can pull in our submodules. If you don’t need your pipeline to run any git commands you can leave your artifact formats set to “CodePipeline default”. Finally, AWS will present you with a warning that you will need to provide CodeBuild with additional permissions to actually run git commands. We will cover that step later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*nKEXuiR37PR15ek8mt0kTw.png" /><figcaption>Recommended settings for the Source section of CodePipeline.</figcaption></figure><h3>Build</h3><h4>Project configuration</h4><p>Now things get interesting. In the build stage, select AWS CodeBuild. Then in the Project name section select “Create project”. We’re going to create a new build project for a specific Unity version. Any new pipelines you create later on can use this same build project we’re about to create. The only reason you will need to create new build projects is if you want to support a different version of Unity.</p><blockquote>Let’s take a quick dip over to Game.ci’s official <a href="https://hub.docker.com/r/unityci/editor/tags">docker hub page</a>. Under the Tags tab is an extensive list of Unity versions and build targets. You’ll need to find the image that matches your targeted version and platform. In my case I want the current LTS version made for Windows so I’ll use:<br><strong><em>unityci/editor:ubuntu-2020.3.21f1-windows-mono-0.15.0<br></em></strong>Save this address as we’ll be using it shortly.</blockquote><p>You should be looking at a “Create build project” window that popped up when you click “Create project” on the previous page. Give this project a name. I recommend using the Unity version as this build project could potentially be used for many different application/games. In this example my build project is named:<br><strong><em>unity-2020_3_21f1-windows-mono-0_15_0</em></strong></p><p>Select “Restrict number of concurrent builds this project can start” and make sure it is set to 1. Because of the way Unity licenses work, we have to “check out” a license during build, and that license isn’t returned until the build is finished. If we attempted simultaneous builds, all builds past the first would immediately fail.</p><h4>Environment</h4><p>Select “Custom image”. For Environment type select “Linux”. The environment type represents the Host system the docker container will run on and isn’t related to our target Unity build platform.</p><p>For the Image registry select “Other registry”. In the External registry URL field, paste the image URL we retrieved from Game.ci’s docker hub page. In our example case that’s: <br><strong><em>unityci/editor:ubuntu-2020.3.21f1-windows-mono-0.15.0</em></strong></p><p>Remember at the beginning of this article when we created a secret containing our Dockerhub username and password? It’s time to use the ARN for that secret. Paste that ARN into the Registry credential field.</p><p>Expand the “Additional configuration” section. We need to create three environment variables. Our build spec file is expecting three variables, <strong><em>UNITY_EMAIL</em></strong>, <strong><em>UNITY_PASSWORD</em></strong>, and <strong><em>UNITY_SERIAL</em></strong>. We set these in the build project so that 1) we’re not storing our Unity login details in a Git repo and 2) so that any additional pipelines setup to use this build project don’t need to worry about setting up authentication. This is also, unfortunately, why we require a Unity Pro or Enterprise account. Personal accounts don’t have a serial and can’t be authenticated from the command line.</p><h4>Buildspec</h4><p>Assuming you’re using our example <strong><em>buildspec.yml</em></strong> file and storing it in the root of your repo, we don’t need to make any changes in the Buildspec section. In fact, we don’t need to make any changes to the Batch configuration or Logs sections either. Here’s what our final CodeBuild project looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*ZxGEwL_8wIv5eyxcqVb0TQ.png" /><figcaption>Full example of a CodeBuild project for building Unity3D apps using <a href="https://game.ci/">Game.ci</a> docker images.</figcaption></figure><p>At last, we are returned to “Add build stage” with our newly created CodeBuild project selected. Simply click Next to reach the final stage of our pipeline creation journey.</p><h3>Deploy</h3><p>Because this is a Unity app, we’re simply going to deploy to an S3 bucket where any interested parties can download our Unity app. Select “Amazon S3” from the Deploy provider dropdown. Then choose the bucket you’d like to drop it in.</p><p>I’d like to leave you with one last neat tip before we close out this article. I like to name my artifacts with both the semantic version of the source code as well as the build number. To do that, we “exported” some variables in our buildspec.yml file. CODEBUILD_BUILD_NUMBER is generated by AWS, but BUILD_OUTPUT_NAME and SEM_VERSION<strong><em> </em></strong>we created and set. In order to use them, we set the “S3 object key” to the following value:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f24554817b30af19df5294df86ca682f/href">https://medium.com/media/f24554817b30af19df5294df86ca682f/href</a></iframe><p>That’s quite a bit of text, but will result in a nicely organized S3 bucket. With this object key, our project would be dropped into the following folder:<br><strong><em>YOUR-APPLICATION/prod/YOUR-APPLICATION-v0.0.1+b1.zip</em></strong></p><p>If you don’t plan on using the same S3 bucket for multiple projects, you can remove the first part of the folder path. Likewise, if you don’t intend to have multiple pipelines for “production”, ”staging”, and “development” you can remove the second directory. (Set here to “prod”.)</p><p>Click Next and you’ll be given a chance to review your pipeline. Give this a quick glance and once satisfied with your handiwork, click “Create pipeline”.</p><h3>Additional Privileges for CodeBuild</h3><h4>Fail First</h4><p>After a few moments your pipeline will be created and it will attempt to do its first build. Unfortunately for us, it’s going to fail, assuming you selected the “Full clone” option during the source stage. If you didn’t, then your project will build successfully and you’re done with this article!</p><p>For everyone else, it’s time for us to make good on our promise to AWS and give our build project the additional privileges it needs to make requests to Bitbucket.</p><p>Go to CodeBuild and find the list of CodeBuild projects. The easiest way to do this is to type in CodeBuild in the AWS Console search field at the top of the page. You will be brought to a list of all your CodeBuild projects, including the one we just created. Select it.</p><p>Next, find the “Build details” tab near the center of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*KwFV9wAZZpTlpf462RvXEg.png" /><figcaption>Location of the “Build details” button.</figcaption></figure><p>Once selected, you will see a “Environment” section near the bottom of the page that has a link to the service role for this build project. Click it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*QxYlv4LXpdTIQPkNfAhnCA.png" /><figcaption>Location of the link to the Service role that was created for our CodeBuild project.</figcaption></figure><h4>IAM</h4><p>You will be brought to the IAM page for the service role of this build project. We need to create a new policy that gives your service role access to our Bitbucket connection. Click “Attach policies”. You will be brought to a list of all the permission policies associated with your AWS account. The majority of which are AWS managed. We need to create a new policy. Click “Create policy.”</p><p>We don’t want the Visual editor, click the “JSON” tab. Add the following JSON to the editor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62899f240c995ec46d4063d8ed0a62df/href">https://medium.com/media/62899f240c995ec46d4063d8ed0a62df/href</a></iframe><p>This policy, when attached to the CodeBuild project, will allow your CodeBuild project to use any Codestar connections. Codestar is used to make our connection to Bitbucket.</p><blockquote>If you would like to segregate connection access, or simply don’t like the idea of a policy that grants blanket codestar access, you can replace the “Resource” section with the ARN of the specific codestar connection you want to grant access to.</blockquote><p>Click “Next: tags”, then “Next: Review”. Name your policy something that will be easy to find for later projects. For example, “aws-bitbucket-connection”. Hit “Create Policy” and your policy will be created.</p><p>Unfortunately, this new policy is not automatically attached to your CodeBuild project. Go back to the tab that has the “Attach permissions” window open for your CodeBuild project. Hit the refresh button contained inside the page in the top right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*Xlz75A189pRdekpUXvVYjA.png" /><figcaption>Location of the refresh button. NOT to be confused with the refresh button of the browser.</figcaption></figure><p>Next in the search field, enter the name of your newly created policy “aws-bitbucket-connection”. Check the box to the left of the policy. Finally, at the bottom of the page, select “Attach policy.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*yQ-jDRFmDT5RlvvUG5GpeQ.png" /><figcaption>Celebratory image detailing the final button we need to click.</figcaption></figure><p>And that’s it! Our pipeline is finally created.</p><h3>Let’s See Results</h3><p>Because our first build failed, let’s manually release another build. Return to your CodePipeline page for this project by searching up “CodePipeline” and selecting your newly created pipeline.</p><p>In addition to builds being released whenever a change is detected in Git on the selected branch, you can also release a build manually by clicking “Release change” in the upper right corner. When your pipeline runs successfully, your pipeline status page should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*xJ7P5a6rChXViixx81a9ag.png" /><figcaption>Example of a status page for a functioning pipeline.</figcaption></figure><p>If you click the “Amazon S3” link you will be brought to the bucket that contains your project.</p><h3>Next Steps</h3><p>This article was put together hastily in order to address the lack of information on this subject. If you encountered issues with the steps laid out here, or just want to speak with smart folks who might have a better approach, I encourage you to join the official <a href="https://game.ci/">Game.ci</a> discord.</p><p>Thinking about joining Medium? Joining through my <a href="https://medium.com/@pixelcurio/membership">referral link</a> is a great way to gain access to mountains of quality content and to buy me a coffee in the process.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e5fc164d197" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Lesson Plan for Learning Shaders (In Unity)]]></title>
            <link>https://medium.com/@pixelcurio/a-lesson-plan-for-learning-shaders-in-unity-ce151d4e9580?source=rss-9bb6c5ba1e6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce151d4e9580</guid>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[shader-in-unity]]></category>
            <dc:creator><![CDATA[Michael Sanders]]></dc:creator>
            <pubDate>Wed, 20 Feb 2019 19:00:30 GMT</pubDate>
            <atom:updated>2019-11-01T16:40:57.399Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*luf0P5eNLcfNIytaFZD_lw.png" /></figure><p>Shaders are powerful. And the resources out there to learn them are plentiful. But when you’re first entering the world of shaders, that bounty can lead to confusion. Where do you start? Which information is outdated? How do you test yourself on what you’ve learned?</p><p>It is relatively simple to google up an “Introduction to Shaders” article. There are great ones all over the internet. Hell, I’ve even written a series that can be used as an intro to shaders <a href="https://medium.com/@pixelcurio/jelly-shader-part-1-project-set-up-83c76d03a354">on this very website</a>. The real problem shows up right after you finish that first article or series. Where do you go next? You don’t yet know what you don’t know.</p><p>Enter the <strong><em>Lesson Plan.</em></strong></p><p>This isn’t exactly a novel concept. The universities have been doing it for at least <a href="https://en.wikipedia.org/wiki/University_of_Al_Quaraouiyine">the last 1160 years</a>. Having one to help guide us through learning shaders in Unity will cut down our time to learn dramatically.</p><p>That’s what this article is. A first draft of a lesson plan for learning shaders in Unity. The series assumes no prior knowledge of shaders, although it does presume some basic experience with Unity.</p><h3>The First Steps</h3><h4>Step 1) <a href="https://www.patreon.com/posts/how-i-got-with-19042499"><strong>How I Got Started with Shaders (Non-Scary Shader Intro)</strong></a></h4><p>This article written by <a href="https://www.patreon.com/minionsart">Minions Art</a>, is the most gentle introduction to shaders I’ve ever encountered. It’s easy to follow and will give you immediate results. Even if you don’t follow any other steps in this lesson plan, this article alone will get you at least playing with and modifying a basic shader.</p><h4><strong>Step 2) </strong><a href="https://www.alanzucconi.com/2015/06/10/a-gentle-introduction-to-shaders-in-unity3d/"><strong>A Gentle Introduction to Shaders in Unity3D</strong></a></h4><p>A second intro article, but whereas the first article glossed over a lot of finer details for the sake of getting you up and running with a shader as fast as possible, this article is going to get into the nitty gritty. Every bit of code that Unity adds to the shader for you will be explained as well as a high level overview of Unity’s render system.</p><p>There will be some redundant info here, but if this is your first concerted effort into learning shaders, that redundancy will work in your favor, both for comprehension and retention.</p><p>If Step 1 was the most important to get you up and running, this step is the most important to make sure you have the necessary background to keep running.</p><h4>Step 3) <a href="https://www.alanzucconi.com/2015/06/17/surface-shaders-in-unity3d/">Surface Shaders in Unity3D</a></h4><p>For our third article, we’re going to stay with the amazing <a href="https://www.alanzucconi.com/">Alan Zucconi</a> and do the second part of his shader intro series. This article will delve more into the Unity-specific “surface shaders” as well as lead you through some example shaders as he explains the concepts.</p><p>After making it through these three articles you have the beginnings of a strong foundation for shader development. If you’re still feeling like your comprehension for these beginning steps is a little shaky, that’s ok! Shader development is a very different way of thinking for a lot of developers and it takes time to understand it at an intuitive level.</p><p>For now, we’re going to move on to the next section. You can always come back to these first three articles after you’ve tried a few from the second section.</p><blockquote><strong>Optional Step</strong></blockquote><blockquote>A lot of these shaders are going to rely on noise textures. For a bit of extra credit, you can go through this tutorial <a href="https://catlikecoding.com/unity/tutorials/noise/">here</a> by <a href="https://catlikecoding.com/">CatLikeCoding</a> that goes through the process of creating perlin noise textures in Unity 3D. Or if you’d rather just jump into other parts of shader development, you can grab a pack of free noise textures <a href="https://80.lv/articles/free-noise-textures-for-vfx/">here.</a></blockquote><h3>Choose Your Own Adventure</h3><p>Now comes the fun part. You’re going to want to take a brief look through each of these tutorial lists and pick the shaders that sound the most exciting to you. Two of the authors you’ve already encountered. They are:</p><ol><li><a href="https://www.alanzucconi.com/tutorials/"><strong>Alan Zucconi</strong></a><strong><br></strong>The most technical on this list, Alan releases incredibly detailed and full featured tutorials that will take you through all the steps necessary to create the shader referenced. You’ll want to browse the list linked here for anything tagged “Unity” and “Shader.”</li><li><a href="https://www.patreon.com/posts/tutorial-list-10663597"><strong>Joyce [Minions Art]</strong></a><br>If anyone on this list is going to draw you in with pure artistic vision, it’s Joyce. The tutorials themselves come in a novel gif format that makes them easy to visualize. The text itself though can be sparse, so it can sometimes be best to use these as little mini tests of your acquired shader knowledge. The source code for all the effects are also available to donors on Joyce’s patreon.</li><li><a href="https://www.youtube.com/channel/UCEklP9iLcpExB8vp_fWQseg/videos"><strong>Dan Moran</strong></a><br>Another class act, Dan releases his tutorials in the form of video “case studies” where he breaks down effects from AAA games. Easy to follow, entertaining, and the source code for all the effects is available in the video’s description.</li></ol><h3><strong>Example Lesson Plan</strong></h3><p>If looking through these lists is still a bit overwhelming, or you just want a more curated experience, here’s one possible path you could take to cover a wide variety of shader topics.</p><ol><li><a href="https://www.patreon.com/posts/how-i-got-with-19042499">How I Got Started with Shaders</a></li><li><a href="https://www.alanzucconi.com/2015/06/10/a-gentle-introduction-to-shaders-in-unity3d/">A Gentle Introduction to Shaders in Unity3D Part 1</a></li><li><a href="https://www.alanzucconi.com/2015/06/17/surface-shaders-in-unity3d/">A Gentle Introduction to Shaders in Unity3D Part 2</a></li><li><a href="https://www.alanzucconi.com/2015/07/08/screen-shaders-and-postprocessing-effects-in-unity3d/">Basics of Image Effects Written</a><br>An introduction to replacement shaders.</li><li><a href="https://www.youtube.com/watch?v=kpBnIAPtsj8">Basics of Image Effects Video</a><br>A second quick look at replacement shaders.</li><li><a href="https://www.youtube.com/watch?v=LnAoD7hgDxw">Pokemon Battle Transitions</a><br>Further exploration of full screen effects.</li><li><a href="https://www.ronja-tutorials.com/2018/12/15/dissolve.html">Texture Based Dissolve</a><br>Quick and dirty intro to discarding pixels.</li><li><a href="https://www.alanzucconi.com/2016/10/02/3d-printer-shader-effect-part-1/">3D Printer Effect Part 1</a><br>Deeper dive into discarding pixels.</li><li><a href="https://www.alanzucconi.com/2016/10/02/3d-printer-shader-effect-part-2/">3D Printer Effect Part 2</a><br>Continuation of the discarding pixels deep dive.</li><li><strong>Challenge:</strong> <a href="https://www.patreon.com/posts/quick-game-art-11304399">Toon Dissolve</a><br>Test your knowledge on discarding pixels by recreating this shader.</li><li><a href="https://www.patreon.com/posts/non-scary-shader-20430343">Intro to Vertex Manipulation</a><br>A beginner’s intro to manipulating vertices in your shader.</li><li><a href="https://www.alanzucconi.com/2017/06/20/tentacle-suckers-shader/">Vertex Manipulation for Tentacles</a><br>Another Alan Zucconi special. We continue our exploration of the vertex portion of shaders by creating a shader for manipulating the “suckers” on a tentacle.</li><li><strong>Challenge:</strong> <a href="https://www.patreon.com/posts/quick-game-art-13724221">Moving Grass</a><br>Take what you’ve learned about vertex manipulation and try and create this shader.</li><li><a href="https://catlikecoding.com/unity/tutorials/flow/texture-distortion/">Texture Distortion</a><br>Jump in deep with CatLikeCoding’s Texture Distortion tutorial.</li><li><strong>Challenge:</strong> <a href="https://www.patreon.com/posts/quick-game-art-16438429">UV Distortion</a><br>See if you can take what you learned in the last tutorial and create this UV distortion tutorial.</li></ol><p>There you have it, the first revision of our Unity shader lesson plan. I may create an updated version of this list later on if people find this resource helpful. So please, if you do go through this list, send me some feedback! Let me know if you hit any snags or know of other resources that would fit well in this list.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce151d4e9580" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jelly Shader, Part 7: Project Clean-Up and Final Steps]]></title>
            <link>https://medium.com/@pixelcurio/jelly-shader-part-7-project-clean-up-and-final-steps-7246913ae828?source=rss-9bb6c5ba1e6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7246913ae828</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Michael Sanders]]></dc:creator>
            <pubDate>Thu, 15 Mar 2018 00:00:00 GMT</pubDate>
            <atom:updated>2018-07-12T22:49:24.236Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*lguFGGxY5dF5MgtL.jpg" /></figure><p><strong>Part 7 — Project Clean-Up and Final Steps</strong></p><p>This is article 7 in our multi-part series on developing a custom shader for Unity 3D. In the final article in this series we will focus on last touch-ups that will make this shader usable in your next project.</p><p>Our project is now mostly complete, but I’d like to add one more variable to the shader and make our shader values configurable from inside the editor. First, inside the subshader, we’re going to modify all our static variables to be non-static. We’re also going to add a new variable to the bottom of the list called _WaveSpeed. That section of your subshader should look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0696a721916bf20219e285067c08068b/href">https://medium.com/media/0696a721916bf20219e285067c08068b/href</a></iframe><blockquote><strong>The Mysterious Disappearing Assignment</strong></blockquote><blockquote>You may have noticed that we also removed the assignment operation from our declaration. Now that these variables are no longer marked as static, we can’t assign them in their declaration. They will be overwritten when the shader is initialized. This is fine though because we will be passing in values for these variables from our UI.</blockquote><p>We also need to expose all these variables to the editor, to do that, add them to the properties section of our shader.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4224d9bbd86e0d39cd942a9596e4da13/href">https://medium.com/media/4224d9bbd86e0d39cd942a9596e4da13/href</a></iframe><p>Next we need to actually include _WaveSpeed in our vertex calculation. Add it here.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a20bbaa0b824b1983a746ae870f696c/href">https://medium.com/media/0a20bbaa0b824b1983a746ae870f696c/href</a></iframe><p>Fantastic! Our shader is now complete and all of our configuration values are editable from the inspector. I’ve tried to include some sensible defaults for an interesting jelly effect but feel free to play with the values and find your own interesting effects. To find those values in the editor, select the sphere inside the Unity editor and expand the JellyMaterial component near the bottom of the Inspector. The final shader and script code is pasted below for your convenience.</p><blockquote>You can also find the final code along with example model <a href="https://www.assetstore.unity3d.com/en/#!/content/106980">on the asset store.</a></blockquote><h4>JellyShader.shader</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55a74663ad58f985a5b1dd08f451685d/href">https://medium.com/media/55a74663ad58f985a5b1dd08f451685d/href</a></iframe><h4>JellyClickReceiver.cs</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d983ef39dfe832c37f5e7655e433c4a/href">https://medium.com/media/6d983ef39dfe832c37f5e7655e433c4a/href</a></iframe><p><em>Originally published at </em><a href="http://heliosinteractive.com/jelly-shader-part-7/"><em>heliosinteractive.com</em></a><em> on March 15, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7246913ae828" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jelly Shader, Part 6: Omni-Directional Movement Axis]]></title>
            <link>https://medium.com/@pixelcurio/jelly-shader-part-6-omni-directional-movement-axis-9e4b907e53e9?source=rss-9bb6c5ba1e6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e4b907e53e9</guid>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Michael Sanders]]></dc:creator>
            <pubDate>Fri, 02 Mar 2018 00:00:00 GMT</pubDate>
            <atom:updated>2018-07-12T23:33:38.932Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*ttaGps07s0tFSuYU.jpg" /></figure><p><strong>Part 6 — Omni-directional Movement Axis</strong></p><p>This is article 6 in our multi-part series on developing a custom shader for Unity 3D. In this article we will add even more life to our sine wave by giving it a more dynamic movement axis.</p><p>Currently, our waves only move along the x-axis. While we could make this work inside Unity using rotations, the better and more robust solution is to allow the shader to handle any potential axis. To do that, we’ll need to use a little trigonometry-magic.</p><p>First we need to provide our shader with some more information. Let’s pass along the location in world space where our mouse click collided with the model and the location in world space of the model’s center. Add the following lines right after we set controlTime to zero.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ca58a5e90bb08eb33fccb4da0ea2208/href">https://medium.com/media/3ca58a5e90bb08eb33fccb4da0ea2208/href</a></iframe><p>This time, instead of using SetFloat we’re using SetVector because we’re passing along the a 3 dimensional vector and not a float. It should be noted _ModelOrigin and _ImpactOrigin don’t actually exist yet in our shader, let’s fix that. As usual, define the shader variables in the standard way; once in the properties section and once inside the sub shader.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07a96e8a7a26783ee2bb0bc1cc4d4c0c/href">https://medium.com/media/07a96e8a7a26783ee2bb0bc1cc4d4c0c/href</a></iframe><p>Great! Now we have access to the model’s position and the impact position. Next, let’s create a new float4 vector called direction that represent the direction our wave will travel across the model. Add this line near the top of the vert function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56a85b154d020e6d1037bcd86de7eb83/href">https://medium.com/media/56a85b154d020e6d1037bcd86de7eb83/href</a></iframe><p>_ModelOrigin – _ImpactOrigin will give us a wave that moves from the impact location towards the center of the model.</p><p>Our origin definition now needs a significant change. We’re going to take the basic formula we’re applying to the x component currently, and apply it to whole vectors. The “1.0” we were using as the start of our wave can now be represented by _ImpactOrigin. _ControlTime * _ImpactSpeed can stay largely the same, except they’re just scalars, so to bring them into 3D space and to give them a direction, multiply them by our direction vector. We also replaced the “-” in the formula with a “+” as the direction information is now included inside of direction. This gives us this final formula.</p><p>float4 origin = _ImpactOrigin + _ControlTime * _ImpactSpeed * direction;</p><p>There’s one more step of intermediary work we need to get to. Currently our _ImpactOrigin and directionvectors are in world space, for the next section we’re going to need those variables in object space, so let’s convert them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2bf691322f399e1f9b19580440ffd69d/href">https://medium.com/media/2bf691322f399e1f9b19580440ffd69d/href</a></iframe><p>Just like we used unity_ObjectToWorld earlier to bring our vertex position into worldspace, we’re now doing the opposite and using unity_WorldToObject to bring our world position coordinates into model space.</p><p>At the beginning of this section I mentioned “trigonometry magic.” Our vertex modification statement currently looks like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69a6bec688183856f925b5cd34c74be7/href">https://medium.com/media/69a6bec688183856f925b5cd34c74be7/href</a></iframe><p>Notice the v.vertex.x part of the formula? This all works great as long as we only want our waves to move along that x axis. To free of ourselves of that, we need a value that represents the axis our wave is traveling along from impact point to model origin. We’ll call that axis value impactAxis. It’s value is equal to the following formula.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c579cc75bc510caa8dea4d2eda4dea6/href">https://medium.com/media/4c579cc75bc510caa8dea4d2eda4dea6/href</a></iframe><blockquote><strong>Trigonometry Magic</strong></blockquote><blockquote>Explaining what’s going on with this formula is unfortunately way outside the scope of this article. Nor would I be able to explain it in a satisfactory manner if it were. But if you are intensely curious, the formula was adapted from this StackOverflow <a href="https://stackoverflow.com/questions/5227373/minimal-perpendicular-vector-between-a-point-and-a-line/5227626#5227626"><strong>answer</strong></a>. With P represented by v.vertex, D represented by l_direction, and A represented by l_ImpactOrigin.</blockquote><p>Now that we have this impact axis, we no longer need to rely on v.vertex.x inside our vertex modification function. So let’s replace it with our new impactAxis.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cfed65d90905e0db019c514ad5b5a31/href">https://medium.com/media/2cfed65d90905e0db019c514ad5b5a31/href</a></iframe><p>At this stage you should be able to fire up Unity and test out the app. Click anywhere on the sphere and a new wave should appear from that location.</p><blockquote><strong>Invisible Sphere</strong></blockquote><blockquote>If when you first fire up the app your sphere has vanished, click where the sphere should be and it should reappear. This just means your _ImpactOrigin is starting at (0,0,0,0). To fix this, select the sphere inside the Unity editor, expand the JellyMaterial component near the bottom of the Inspector, and change the Impact Origin to be (-5,0,0,0).</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/0*g5eWfgh0LFMd_Gsk.png" /></figure><p>The final code for your shader should look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cfb7bca27f1269b5dc863b7e229d0e4/href">https://medium.com/media/3cfb7bca27f1269b5dc863b7e229d0e4/href</a></iframe><p><em>Part 7 of this series can be found </em><a href="https://medium.com/@pixelcurio/jelly-shader-part-7-project-clean-up-and-final-steps-7246913ae828"><em>here.</em></a></p><p><em>Originally published at </em><a href="http://heliosinteractive.com/jelly-shader-part-6/"><em>heliosinteractive.com</em></a><em> on March 2, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e4b907e53e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jelly Shader, Part 5: Player Interaction]]></title>
            <link>https://medium.com/@pixelcurio/jelly-shader-part-5-player-interaction-afe2eb735908?source=rss-9bb6c5ba1e6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/afe2eb735908</guid>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Michael Sanders]]></dc:creator>
            <pubDate>Wed, 28 Feb 2018 00:00:00 GMT</pubDate>
            <atom:updated>2018-07-12T23:32:38.127Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*9IfnMEVl5pSYoGXY.jpg" /></figure><p><strong>Part 5 — Player Interaction</strong></p><p>This is article 5 in our multi-part series on developing a custom shader for Unity 3D. In this article we will be adding player input to our JellyClickReceiver so users can interact directly with the shader from the scene.</p><p>Let’s start adding interactivity to our sphere. Add the following lines to the middle of your update function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da9edc9b4ddda326ec6201a5b2ac90e6/href">https://medium.com/media/da9edc9b4ddda326ec6201a5b2ac90e6/href</a></iframe><p>Your update function should now look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/052652939080ada3a1ea7cd958805f1e/href">https://medium.com/media/052652939080ada3a1ea7cd958805f1e/href</a></iframe><p>All this extra bit of code is doing is resetting our controlTime to 0 whenever the primary mouse button is clicked, resetting our wave animation. So we can enjoy our little wave animation over and over and over. But, I think we can do better. Let’s make our animation only reset if we click on the sphere.</p><p>First, select the gameobject for your model that contains our MeshRender and JellyClickReceiver then click “Add Component.” From the Add Component menu that pops up, find SphereCollider and select it.</p><p>This should add a sphere collider that pretty accurately fits our model. (Assuming you’re using the example sphere model. If not, try and fit the collider as closely to the model as possible. Feel free to use a collider other than sphere if it would fit your model better.)</p><p>Now we need to add some more code to JellyClickReceiver.cs. First define two more private variables of types RaycastHit and Ray.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9417a378e20984ef694f7b70c37af62/href">https://medium.com/media/d9417a378e20984ef694f7b70c37af62/href</a></iframe><p>Right now, we reset our controlTime to zero as soon as the mouse button is clicked. For this next step, when the mouse button is clicked, a ray will be cast from the click location into our scene and if it hits something, we reset our controlTime to zero. Let’s start by defining that ray. Add the following line inside the ‘if’ block inside our update function.</p><p>clickRay = Camera.main.ScreenPointToRay(Input.mousePosition);</p><p>ScreenPointToRay is a useful function built into Unity cameras that takes a screen space position and constructs a world space ray that goes from the selected camera through the provided screen position.</p><blockquote><strong>Screen Space vs World Space</strong></blockquote><blockquote>If you’d like a deeper explanation of screen space vs world space, there’s a great answer on the Unity Answers site here. <a href="https://answers.unity.com/questions/256817/about-world-space-and-local-space.html?childToView=256837#answer-256837"><strong>here</strong></a></blockquote><p>Next we need to cast that ray. Add the following lines directly after our clickRay assignment.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3bf6ad1e7b9688e081f8eb37b3db8fc/href">https://medium.com/media/a3bf6ad1e7b9688e081f8eb37b3db8fc/href</a></iframe><p>Physics.Raycast casts an invisible particle along the ray provided by clickRay and if it hits any colliders along the way, it returns true and provides information about the collision (such as what it collided with and where) in the variable hit. Later on, we will use the additional information provided by hit, but for now, if we hit anything we reset our shader.</p><p>Your Update function should look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04d3ba7e50eb7f1894bf0e50095bbd04/href">https://medium.com/media/04d3ba7e50eb7f1894bf0e50095bbd04/href</a></iframe><p>That’s all for this article. In the next part of this series we will dive deeper into our sine wave’s movement axis.</p><p><em>Part 6 of this series can be found </em><a href="https://medium.com/@pixelcurio/jelly-shader-part-6-omni-directional-movement-axis-9e4b907e53e9"><em>here.</em></a></p><p><em>Originally published at </em><a href="http://heliosinteractive.com/jelly-shader-part-5/"><em>heliosinteractive.com</em></a><em> on February 28, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afe2eb735908" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jelly Shader, Part 4: Integration With Unity]]></title>
            <link>https://medium.com/@pixelcurio/jelly-shader-part-4-integration-with-unity-b3353cf0760d?source=rss-9bb6c5ba1e6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3353cf0760d</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[Michael Sanders]]></dc:creator>
            <pubDate>Wed, 28 Feb 2018 00:00:00 GMT</pubDate>
            <atom:updated>2018-07-12T23:32:06.211Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*ghIXWgemNZfyyehA.jpg" /></figure><p><strong>Part 4 — Integration With Unity</strong></p><p>This is article 4 in our multi-part series on developing a custom shader for Unity. In this article we will be modifying our shader so it can receive input from scripts in our scene.</p><p>Let’s start by replacing the built-in _Time value with a value we provide ourselves. Allowing us to reset the wave animation at will. Let’s call this new variable _ControlTime and add it to variable declarations. Add to the property block:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09b3f7f10e0722da0b817cb6a3010132/href">https://medium.com/media/09b3f7f10e0722da0b817cb6a3010132/href</a></iframe><p>And to the subshader:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfbf48c1d7a430dc1a8e3b910d5ecb51/href">https://medium.com/media/dfbf48c1d7a430dc1a8e3b910d5ecb51/href</a></iframe><p>We also need to replace any references to _Time. There should be two. One at the origin declaration and another when we modify the vertex position. Those lines should look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6746a3944e6291de50119bcae455117/href">https://medium.com/media/e6746a3944e6291de50119bcae455117/href</a></iframe><p>Our shader is now setup to use this new time. Now we need to create a C# script to attach to our model that will update this new value. Inside of our Unity project, create a new C# script titled JellyClickReceiver.cs. Once the file has been created and named, attach it to your 3D model so that it’s on the same gameobject as the Mesh Renderer for your model. The scene setup for our example model looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tjECYoZrfUxPLY39.png" /></figure><p>Now to edit JellyClickReceiver.cs. First we need to declare two variables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37c73225b3cbf73eae95d0eeddd5302a/href">https://medium.com/media/37c73225b3cbf73eae95d0eeddd5302a/href</a></iframe><p>The variable modelRenderer will just be used to cache our MeshRenderer component.</p><blockquote><strong>Component Caching</strong></blockquote><blockquote>Lookup functions like GetComponent aren’t generally very efficient, so any time you plan to access a component in the Update function (or more than once anywhere in your app) you should greatly consider caching the component instead and only looking it up once. As usual, a more elaborate explanation is available on the <a href="https://docs.unity3d.com/353/Documentation/ScriptReference/index.Performance_Optimization.html"><strong>official Unity docs</strong></a> under section 3 “Cache component lookups.”.</blockquote><p>All we’re going to do in our Start function (for now) is cache our MeshRenderer.</p><p>modelRenderer = GetComponent();</p><p>And in our Update function we’re going to do two things:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b92f014e394c0dfd23b63ea0fa7bbc5d/href">https://medium.com/media/b92f014e394c0dfd23b63ea0fa7bbc5d/href</a></iframe><p>First we’re going to add to our controlTime with the current deltaTime to act as a running clock. UnityEngine.Time already has a property built in to track total time, but we’re going to be resetting controlTime later, something we can’t do with UnityEngine.Time.</p><p>Next is the fun part, we access the material associated with our MeshRenderer and call SetFloat. This function passes variables from your C# script to your shader. All you need to do is tell it the name of the variable you want to set inside the shader, and the value you want to set it to.</p><p>At this point, you should be able to fire up Unity and run the application, and if everything was done right, it should look…exactly the same! Your wave should slowly animate from one side of your sphere to the other. Your final script should look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afb890b476c20aec94efb1b24bf0e1a8/href">https://medium.com/media/afb890b476c20aec94efb1b24bf0e1a8/href</a></iframe><p><em>Part 5 of this series can be found </em><a href="https://medium.com/@pixelcurio/jelly-shader-part-5-player-interaction-afe2eb735908"><em>here.</em></a></p><p><em>Originally published at </em><a href="http://heliosinteractive.com/jelly-shader-part-4/"><em>heliosinteractive.com</em></a><em> on February 28, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3353cf0760d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jelly Shader, Part 3: Trailing Sine Wave]]></title>
            <link>https://medium.com/@pixelcurio/jelly-shader-part-3-trailing-sine-wave-ef2c4a267801?source=rss-9bb6c5ba1e6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef2c4a267801</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Michael Sanders]]></dc:creator>
            <pubDate>Mon, 26 Feb 2018 00:00:00 GMT</pubDate>
            <atom:updated>2018-07-12T23:31:39.629Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*ypjnZI2I6F501_f9.jpg" /></figure><p><strong>Part 3 — Trailing Sine Wave</strong></p><p>This is article 3 in our multi-part series on developing a custom shader for Unity 3D. In this article we will be modifying our sine wave function so instead of moving uniformly across the surface of our sphere it appears to “travel” across the surface.</p><p>First, let’s create a few parameters we’ll use later to control the look of our wave. Add the following lines right below _Amplitude.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40343b75139b3b300bce4f782a91c5ea/href">https://medium.com/media/40343b75139b3b300bce4f782a91c5ea/href</a></iframe><p>Now, let’s adjust the amplitude of our sine wave based on the distance from the “origin” of our wave. To do that, we’re going to need our vertex’s position in world space, not local to the model. Luckily Unity provides a matrix so we can make that conversion quickly. Add the following line to the top of your vert function.</p><p>float4 world_space_vertex = mul(unity_ObjectToWorld, v.vertex);</p><p>This line simply takes the vertex’s local position and multiplies it by the Unity provided matrix unity_ObjectToWorld which brings the vertex into world space.</p><blockquote><strong>The mul() Function</strong></blockquote><blockquote>There are a number of built-in or intrinsic functions when writing shaders. These are generally consistent across Cg, HLSL, GLSL. For a list of built-in Cg functions please consult this <a href="https://www.sjbaker.org/wiki/index.php?title=Concise_Cg_built-in_function_table"><strong>wiki</strong></a>.</blockquote><p>Now we’re going to create a variable that tracks the origin of our wave. Add the following line right after world_space_vertex.</p><p>float4 origin = float4(1.0, 0.0, 0.0, 0.0);</p><p>Exciting, right? For now, we’re just going to offset our origin slightly to the right of our model. Because our example model is a sphere, if we used 0,0,0 as the origin of the wave the entire sphere would have the same distance and, well, our shader would look the same! If you’re using your own model, you might have to offset this more or less. We will expand on this later to be much more dynamic. Now we need to determine the distance between our vertex and the origin. Luckily the distance() function does just that. Add the following lines to your vert function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b0d66a65772742e023278e40586f3cb/href">https://medium.com/media/0b0d66a65772742e023278e40586f3cb/href</a></iframe><p>These three lines could easily be condensed down to a single line, but I wanted to separate them out so they would be easy to experiment with by adjusting the associated parameter or commenting out completely. The pow function makes it so our waves fall off very quickly as they get farther away from the origin. The max function keeps our waves from going too crazy when the vertex lies directly on, or very near, the origin. Last thing to do is to actually include this value in our vertex calculation line. Update it to the following.</p><p>v.vertex.xyz += v.normal * sin(v.vertex.x * _Frequency + _Time.y) * _Amplitude * (1 / dist);</p><p>You’ll notice we’re adjusting the amplitude based on the <em>inverse</em> of the distance. If we just used dist our waves would get <em>larger</em> the farther we got from the origin. Your sphere should look vaguely like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/0*sLDJx4h-F-5l2IJB.gif" /></figure><p>Now that we have a wave that’s more intense at the wave “origin” let’s make that origin travel across the sphere to simulate a shockwave. First lets add a new property just below _MaxWaveDistortion.</p><p>static half _ImpactSpeed = 0.2;</p><p>And let’s update our origin initializer so that it’s value is offset by _Time.</p><p>float4 origin = float4(1.0 - _Time.y * _ImpactSpeed, 0.0, 0.0, 0.0);</p><p>The x coordinate of our origin will start at 1.0 and move to the left as _Time increases over time with the additional factor of _ImpactSpeed included so we can control how quickly that origin changes.</p><p>I encourage you to take a moment to play with _WaveFalloff, _MaxWaveDistortion, and _ImpactSpeed before moving on to the next article.</p><p><em>Part 4 of this series can be found </em><a href="https://medium.com/@pixelcurio/jelly-shader-part-4-integration-with-unity-b3353cf0760d"><em>here.</em></a></p><p><em>Originally published at </em><a href="http://heliosinteractive.com/jelly-shader-part-3/"><em>heliosinteractive.com</em></a><em> on February 26, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef2c4a267801" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jelly Shader, Part 2: A Basic Sine Wave]]></title>
            <link>https://medium.com/@pixelcurio/jelly-shader-part-2-a-basic-sine-wave-e854aed19f22?source=rss-9bb6c5ba1e6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e854aed19f22</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[Michael Sanders]]></dc:creator>
            <pubDate>Fri, 09 Feb 2018 00:00:00 GMT</pubDate>
            <atom:updated>2018-07-12T23:30:40.054Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*a9RGPZKUBN8mOli_.jpg" /></figure><p><strong>Part 2 — A Basic Sine Wave</strong></p><p>This is article 2 in our multi-part series on developing a custom shader for Unity. In this article we will be modifying our shader to create a basic sine wave that moves along the surface of our 3D model.</p><p>While the default ShaderLab file we created in Part 1 comes with a surface shader (also known as a fragment or pixel shader) function built in, what we need is a vertex shader. A vertex shader allows us to operate on the actual vertex positions and normals of the model instead of just the colors. To do that, first we need to tell Unity that we have a vertex shader. Modify this line:</p><p>#pragma surface surf Standard fullforwardshadow</p><p>to</p><p>#pragma surface surf Standard fullforwardshadow addshadow vertex:vert</p><p>addshadow needs to be added in whenever you plan to modify vertex positions so that Unity makes a shadow caster pass on the object. Otherwise the shadows on your model will be generated based on the model’s original shape.</p><p>vertex: tells Unity that we’re going to be creating a vertex shader and vert tells Unity the name of the function where we’ll be doing that. So next let’s add that function. Right above our surface function, add the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a976088043bdafdc754e49f6100d0090/href">https://medium.com/media/a976088043bdafdc754e49f6100d0090/href</a></iframe><p>appdata_base is a part of another collection of structures provided by Unity. This structure determines what data will be available to use while modifying the vertex. appdata_base contains the following fields:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e851d2de62c27d075855324418ecb1d/href">https://medium.com/media/3e851d2de62c27d075855324418ecb1d/href</a></iframe><p>Now that all that setup is out of the way, let’s actually make something happen. Inside our vert function, add the following line:</p><p>v.vertex.xyz += v.normal * sin(_Time.y);</p><p>Fire up Unity and you should see a sphere growing and shrinking in size. It’s not much, but it’s the start of our jelly shader. Let’s breakdown what’s happening.</p><p>Because v is specified as inout any modifications we make to the vertex will persist to the other stages of the shader. We’re then modifying our vertex’s position, v.vertex.xyz, by moving it along the axis of its normal, v.normal. This creates our breathing motion. How far along we move on that axis is determined by multiplying by our sine function, which we’re feeding a time variable.</p><blockquote><strong>_Time</strong></blockquote><blockquote>_Time is yet another Unity convenience built-in to save us time. _Time is a vector4 prefilled with the following values:</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbcb4003308bab815a7288234e208ccd/href">https://medium.com/media/dbcb4003308bab815a7288234e208ccd/href</a></iframe><p>Just using a plain time variable for our sine wave means our modification is uniform across the entire model. Let’s change that. Define the following variables just below our “_Glossiness”, “_Metallic”, and “_Color” variables:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97c907c0c6ec4afa65dcb5f6b15f95c8/href">https://medium.com/media/97c907c0c6ec4afa65dcb5f6b15f95c8/href</a></iframe><p>For now, ignore the fact that we’ve marked these variables as static. This allows us to assign values on declaration, which is handy, but we will change this later on. Let’s rework our vertex function. First, instead of affecting all vertices the same, let’s have our sine function take into account x position of the vertice:</p><p>v.vertex.xyz += v.normal * sin(v.vertex.x + _Time.y);</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/0*3iIopUmzsz68RWIQ.gif" /></figure><p>At this point our sphere is doing something, but it still doesn’t look like a wave. Let’s try adjusting the frequency of the waves on our sphere:</p><p>v.vertex.xyz += v.normal * sin(v.vertex.x * _Frequency + _Time.y);</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*e9gN8_3SuMbVNVQh7esosQ.gif" /></figure><p>Closer, but the waves are a little intense, let’s knock down the amplitude a bit.</p><p>v.vertex.xyz += v.normal * sin(v.vertex.x * _Frequency + _Time.y) * _Amplitude;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/0*9Yd6A5NFAk7sS2dz.gif" /></figure><p>Alright! Now those look like waves. We now have waves on our model moving along the x-axis (thanks to the &gt;v.vertex.x being inside our sin function) with configurable parameters. At this point, I really encourage you to take a few minutes to play with vertex function and see what other cool effects you can create just by modifying _Frequency, _Amplitude, _Time, and even v.vertex. Here’s our full shader code currently so you can copy and paste it back in when you’re done experimenting.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4858cdae7b76bfc7272b928118c9b35d/href">https://medium.com/media/4858cdae7b76bfc7272b928118c9b35d/href</a></iframe><p><em>Part 3 of this series can be found </em><a href="https://medium.com/@pixelcurio/jelly-shader-part-3-trailing-sine-wave-ef2c4a267801"><em>here.</em></a></p><p><em>Originally published at </em><a href="http://heliosinteractive.com/jelly-shader-part-2/"><em>heliosinteractive.com</em></a><em> on February 9, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e854aed19f22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jelly Shader, Part 1: Project Set-Up]]></title>
            <link>https://medium.com/@pixelcurio/jelly-shader-part-1-project-set-up-83c76d03a354?source=rss-9bb6c5ba1e6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/83c76d03a354</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[shaders]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Michael Sanders]]></dc:creator>
            <pubDate>Wed, 24 Jan 2018 00:00:00 GMT</pubDate>
            <atom:updated>2018-07-12T23:29:58.404Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*LP0agOpmy_SF6zJF.jpg" /></figure><p><strong>Part 1 — Basic Project Setup and Explanation</strong></p><p><em>Setup, Versions, and Requirements: Unity 5.6.0f3 and a model with a high poly-count.</em></p><blockquote><strong>Target Audience</strong></blockquote><blockquote>This series is aimed at Unity developers with little to no shader experience, although basic knowledge of Unity project structure and C# is expected. If you’re feeling a little rusty, the official <a href="https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial"><strong>Unity Tutorials</strong></a> are a great place to start.</blockquote><p>This is article one in our multi-part series on developing a custom shader for Unity. In this article we will be setting up the basic project structure we will use throughout the rest of the article series.</p><p>The shader we’ll be creating will only support models with a high polygon count. This is because we’re going to be trying to show a smooth sine wave along the surface of the model and if the poly count is too low it will just appear choppy and broken. In the future, we may extend this shader to add geometry dynamically, but for the sake of simplicity we’re only going to support high poly models for now.</p><blockquote>If you’re in need of a high poly model, I’ve included one in the example project available <a href="https://www.assetstore.unity3d.com/en/#!/content/106980">on the asset store.</a></blockquote><p>First things first, once you’ve found a suitably high poly model, drag it into your scene. Your basic project should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fXDVbkeMf2wisgU3.jpg" /></figure><p>Next, we need to create a new shader to work with. Right click in the project window and select Create -&gt; Shader -&gt; Standard Surface Shader. Name the new shader “JellyShader.” We now have a basic Unity surface shader. Now let’s create a material that utilizes this shader. Right click JellyShader and select Create -&gt; Material. Rename the new material “JellyMaterial.” This process creates a material that is already assigned to the “JellyShader” shader.</p><blockquote><strong>Materials and Shaders</strong></blockquote><blockquote>If you’re familiar with <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented programming</a> concepts, you can think of a Material as an instance of a shader. Many materials can be assigned to a single shader, each one with slightly different attributes.</blockquote><blockquote><strong>GLSL, CG, and ShaderLab Files</strong></blockquote><blockquote>Shaders can be written in several different, but very similar, languages. Including GLSL, HLSL, and CG. Unity itself uses something called ShaderLab. ShaderLab is an abstraction one level above GLSL or CG that tells Unity how to render a mesh. This ShaderLab file also contains the actual GLSL or CG shader code we’re writing to render our jelly effect.</blockquote><blockquote><strong>Unity Surface Shaders</strong></blockquote><blockquote>When we created our shader, we selected “Standard Surface Shader.” This auto-generated a shader that includes everything the shader needs to use Unity’s built-in lighting effects. This saves us a lot of time and is a great place to start when you’re first learning shaders. More information on Surface Shaders is available on Unity’s <a href="https://docs.unity3d.com/Manual/SL-Reference.html">Shader Reference</a> and <a href="https://docs.unity3d.com/Manual/ShadersOverview.html">Writing Shaders</a>documentation pages.</blockquote><p>Now that we have our material, our last bit of setup is to drag and drop our JellyMaterial onto our sphere. Let’s verify that the shader is attached to our model. In the Hierarchy tab, select your model. At the bottom of the Inspector tab, under Mesh Renderer, it should say “Shader: Custom/JellyShader.” If you don’t see a Mesh Renderer in the inspector tab, you may need to drill down into the children of your model in the Hierarchy tab. For example, if you’re using the model I supplied, the object you’re looking for is “default” which is a child of “High-Poly-Sphere.”</p><p>Once you have found your shader on your model, expand out the shader section. Because we used “Standard Surface Shader” there should already be a number of options built into our shader including, Color, Albedo, Smoothness, and Metallic.</p><blockquote><strong>Physically Based Rendering</strong></blockquote><blockquote>Unity’s Standard Surface Shader uses Physically Based Rendering (PBR.) As usual, consult Unity’s official documentation for a great breakdown on <a href="https://blogs.unity3d.com/2015/02/18/working-with-physically-based-shading-a-practical-approach/">working with PBR.</a></blockquote><p>Feel free to play around here with the material’s color, smoothness, and metallic. I’ve changed my sphere to a soft blue. Now it’s time to actually start writing our shader. Double click JellyShader. It should launch into Visual Studio or Mono. Let’s do a quick breakdown of everything included in this default shader.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/749f2b503e26207c01833a242d6dca6d/href">https://medium.com/media/749f2b503e26207c01833a242d6dca6d/href</a></iframe><p>This first section is listing of variables that should be exposed to the Unity Editor as well as their default values. To actually access these values inside of your shader code, you’ll have to declare variables with the exact same name and the corresponding variable type inside the SubShader portion of the shader file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a81213437230aba8fd5644124267501/href">https://medium.com/media/8a81213437230aba8fd5644124267501/href</a></iframe><p>We’re going to gloss over most of this section. For our shader, we can leave all of this as is.</p><blockquote><strong>A Gentle Introduction</strong></blockquote><blockquote>If you’d like a more thorough explanation of these tags and compiler directives, or just want a better understanding of how shaders function inside Unity, I highly recommend reading Alan Zucconi’s amazing series, <a href="http://www.alanzucconi.com/2015/06/10/a-gentle-introduction-to-shaders-in-unity3d/"><strong>A Gentle Introduction to Shaders in Unity 3D.</strong></a></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f56f399ebdc1df076bb6df2f6add362/href">https://medium.com/media/2f56f399ebdc1df076bb6df2f6add362/href</a></iframe><p>_MainTex, _Glossiness, _Metallic, and _Color, are some of the variables we’ll be using in the creation of our shader. Notice that these are named exactly the same as their Property counterparts. In order to use a variable from the editor, it needs to be exposed in the property section and declared in the body of the shader.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91028b8ff0804ab62f8460cd5928e285/href">https://medium.com/media/91028b8ff0804ab62f8460cd5928e285/href</a></iframe><p>This is another section we’re going to pass on for now. Unity 5.6 added a feature called instancing to it’s shaders. You can read about it <a href="https://docs.unity3d.com/Manual/GPUInstancing.html"><strong>here</strong></a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9dc098c85a281303a2e7f5c5a010694/href">https://medium.com/media/d9dc098c85a281303a2e7f5c5a010694/href</a></iframe><p>Now we’re getting to the good stuff! This section is our surface shader. This code will be run on every pixel in our scene. The first thing to note is SurfaceOutputStandard. Unity has several built in structures for surface function output, including SurfaceOutput, SurfaceOutputStandard, SurfaceOutputStandardSpecular.</p><p>The next line fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; Uses the tex2D function to grab the color for this particular pixel from the texture supplied by _MainTex and tints it with the color supplied by _Color. The final step is to fill out the SurfaceOutputStandard object o with our final values.</p><p>That gives us the basic breakdown of the surface shader Unity created for us. In the next part we will actually start modifying the shader.</p><p><em>Part 2 of this series can be found </em><a href="https://medium.com/@pixelcurio/jelly-shader-part-2-a-basic-sine-wave-e854aed19f22"><em>here.</em></a></p><p><em>Originally published at </em><a href="http://heliosinteractive.com/jelly-shader/"><em>heliosinteractive.com</em></a><em> on January 24, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83c76d03a354" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>