Search Unity

THE DFAULTS - Animate Your Default Capsule - Free Shader

Discussion in 'Assets and Asset Store' started by Fergicide, Feb 16, 2020.

  1. Fergicide

    Fergicide

    Joined:
    Mar 19, 2016
    Posts:
    21
    Personalize your prototype. Give your game jam some groovy.



    To add some flair to my prototyping, I wrote a shader to animate the Unity default capsule. It uses a single material and material property blocks for instancing.

    DOWNLOAD for free from itch.io

    More info here:
    https://sites.google.com/site/unityassetsbyfergicide/news/thedfaults-freeonunityassetstore

    Youtube demo links:





    I was inspired by this January 2020 Reddit post lamenting Unity's humdrum, faceless default capsule, I wondered what else might spruce up the oftentimes joyless exercise of early game prototyping. What if the default capsule could have not just a face but an animated face?

    I am not a seasoned shader coder. But I know enough now to get things working. I set out to write an animation shader that adheres to these design goals: simple, efficient, and based on the default Unity surface shader.

    But how to create a "face"? Well, eyes are just two circles, black within white. I just needed shader code that draws circles. Mouth? If you lay a circle atop another circle and slide it around, you create a crescent mouth-like shape. So that's just six circles to draw: a circle within a circle each for eyes, and two circles to form the mouth.

    Beyond this simple manipulation of a few circles, all I needed now was color. Controlling color via UV coordinates is super easy. Not a problem.

    And that's it. Some circles, some color, some setup scripting and some basic shader code... and we've got THE DFAULTS.

    Early on, I contemplated adding instanced textures but chose not to. Instancing textures requires Texture2DArrays. That would add shader overhead and was not really in the spirit of keeping things simple.

    Running the "WeAreLegion" non-LOD scene in the editor, which creates 15,000 instanced Dcaps, I get these stats:

    - 8 million verts
    - 65 batches, 15K batches saved
    - 3 set pass calls

    The alternate LOD scene tops out at about 500K verts.

    The linked package contains prefabs to get you up and running, but you can ignore those and build your own Dfaults from scratch with these three essential files:

    #1 The Dfaults shader: "DfaultsShader"
    Add to your project and find it under "Fergicide/Dfaults" in the shader library. Create a material from it.

    #2 Scriptableobject: "DfaultsConfig"
    For creating and storing Dfault configurations. To start playing with new configurations, duplicate the existing Dcap configuration file under ASSETS > FERGICIDE > DFAULTS > CONFIGS > DCAPS, then add it to your DfaultsController component.

    #3 Monobehaviour: "DfaultsController"
    To be attached to every Dfault gameobject or prefab. Requires two configuration properties: the Dfaults configuration file and the Dfaults material to use. Create your Unity capsule gameobject, add the "DfaultsController" script to it, then drag a "DfaultsConfig" scriptableobject and the Dfaults material onto the controller script. You are good to go.

    EXTRAS
    - LOD scene
    - Metal variants
     
    Last edited: Mar 22, 2020
    StaticWave and e45240 like this.
  2. patihan70

    patihan70

    Joined:
    Oct 10, 2022
    Posts:
    2
    Sir, I got a problem when I import to 3D URP the materials are pink even I create new and use your shader.