Convert Figma logo to code with AI

keijiro logoSkinner

Special Effects with Skinned Mesh in Unity

3,292
411
3,292
2

Top Related Projects

Video glitch effects for Unity

Object instancing/particle animation system for Unity

Quick Overview

Skinner is a Unity plugin that provides a specialized skinning system for real-time rendering of mesh animations. It focuses on GPU-accelerated skinning techniques to achieve high-performance mesh deformations, making it particularly useful for complex character animations and large-scale mesh manipulations in Unity projects.

Pros

  • High performance due to GPU-accelerated skinning
  • Supports complex mesh deformations and animations
  • Integrates seamlessly with Unity's existing systems
  • Provides a solution for handling large numbers of animated meshes efficiently

Cons

  • Requires understanding of Unity's rendering pipeline and GPU programming concepts
  • May have a steeper learning curve compared to Unity's built-in skinning system
  • Limited documentation and examples available
  • Potential compatibility issues with older hardware or mobile devices due to GPU requirements

Code Examples

  1. Creating a Skinner instance:
using Skinner;

public class SkinnerExample : MonoBehaviour
{
    public SkinnerSource source;
    public SkinnerRenderer renderer;

    void Start()
    {
        var skinner = gameObject.AddComponent<Skinner>();
        skinner.source = source;
        skinner.renderer = renderer;
    }
}
  1. Configuring Skinner parameters:
void ConfigureSkinner(Skinner skinner)
{
    skinner.bufferWidth = 256;
    skinner.bufferHeight = 256;
    skinner.triangleCount = 1000;
    skinner.kernelSize = 8;
}
  1. Accessing Skinner data in a custom shader:
// In your custom shader
sampler2D _SkinnerPositionBuffer;
sampler2D _SkinnerNormalBuffer;

float4 vert(float2 uv : TEXCOORD0) : SV_POSITION
{
    float3 position = tex2Dlod(_SkinnerPositionBuffer, float4(uv, 0, 0)).xyz;
    float3 normal = tex2Dlod(_SkinnerNormalBuffer, float4(uv, 0, 0)).xyz;
    // Use position and normal for further calculations
}

Getting Started

  1. Import the Skinner package into your Unity project.
  2. Add a SkinnerSource component to your animated mesh.
  3. Create a new GameObject and add a SkinnerRenderer component.
  4. In your script, create a Skinner instance and configure it:
using Skinner;

public class SkinnerSetup : MonoBehaviour
{
    public SkinnerSource source;
    public SkinnerRenderer renderer;

    void Start()
    {
        var skinner = gameObject.AddComponent<Skinner>();
        skinner.source = source;
        skinner.renderer = renderer;
        skinner.bufferWidth = 256;
        skinner.bufferHeight = 256;
        skinner.triangleCount = 1000;
    }
}
  1. Attach this script to a GameObject in your scene and assign the SkinnerSource and SkinnerRenderer components in the Inspector.

Competitor Comparisons

Video glitch effects for Unity

Pros of KinoGlitch

  • Focuses on post-processing effects and glitch aesthetics
  • Simpler implementation for quick visual enhancements
  • Easier to integrate into existing Unity projects

Cons of KinoGlitch

  • Limited to 2D visual effects
  • Less customizable than Skinner's mesh-based approach
  • May have higher performance overhead for complex scenes

Code Comparison

KinoGlitch (Analog Glitch effect):

void OnRenderImage(RenderTexture source, RenderTexture destination)
{
    var material = _material;
    var time = Time.time;
    material.SetFloat("_ScanLineJitter", _scanLineJitter);
    material.SetFloat("_VerticalJump", _verticalJump);
    material.SetFloat("_HorizontalShake", _horizontalShake);
    Graphics.Blit(source, destination, material, 0);
}

Skinner (Particle effect):

void Update()
{
    if (_source != null && _source.isPlaying)
    {
        var sourceData = _source.GetParticleData();
        _renderer.SetParticleData(sourceData);
        _renderer.Update(Time.deltaTime);
    }
}

KinoGlitch focuses on post-processing effects applied to the final rendered image, while Skinner manipulates mesh data to create dynamic visual effects. KinoGlitch is more suitable for quick, 2D glitch effects, whereas Skinner offers more complex, 3D particle-based animations.

Object instancing/particle animation system for Unity

Pros of KvantSpray

  • Focuses on particle systems and spray effects, offering more specialized functionality
  • Provides real-time GPU-accelerated particle simulation
  • Includes a custom editor interface for easy parameter adjustment

Cons of KvantSpray

  • Limited to particle-based effects, less versatile than Skinner's mesh deformation capabilities
  • May require more GPU resources for complex particle simulations
  • Less suitable for character or object-based animations

Code Comparison

KvantSpray (particle system initialization):

public void Initialize(int emitterCount, int historyLength)
{
    _emitterCount = emitterCount;
    _historyLength = historyLength;
    _positionBuffer = new ComputeBuffer(_emitterCount * _historyLength, sizeof(float) * 3);
    _velocityBuffer = new ComputeBuffer(_emitterCount, sizeof(float) * 3);
}

Skinner (vertex animation setup):

void Start()
{
    _source = GetComponent<SkinnedMeshRenderer>();
    _template = new Mesh();
    _source.BakeMesh(_template);
    _deformer = new MeshDeformer(_template);
}

The code snippets demonstrate the different focus areas of each project: KvantSpray initializes particle system buffers, while Skinner sets up mesh deformation components.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Skinner

gif gif

Skinner is a collection of special effects that use vertices of an animating skinned mesh as emitting points. It uses a special replacement shader to convert vertex positions into GPU-friendly data, and thus it avoids spending extra memory and CPU time for handling them (uses GPU resources instead).

Skinner Asset Types

Skinner provides some special asset types to preprocess relevant data.

Skinner Model

A Skinner model is a simplified variant of a mesh asset that only has vertices and skin weights. When converted from an original mesh, all the topological data of triangles is removed and overlapped vertices are stripped out.

Skinner Template

A Skinner template is a pre-built mesh asset that provides vertices and topological data to the effect renderers. For instance, a Skinner particle template has thousands of particle instances that are placed at the world origin; A Skinner particle renderer will move them at run time.

Skinner Component Classes

Skinner also provides some component classes to handle these assets during run time.

Skinner Source

The Skinner source component is a subsystem that converts a deformed skinned mesh into baked data. This data will be provided to multiple Skinner renderers.

Skinner Renderers

The Skinner renderer components are special types of mesh renderers that deform a Skinner template based on data provided from a Skinner source. Then it creates some interesting special effects.

How to Set Up

Install the package.

Download one of the unitypackage files from the Releases page and import it into a project.

Convert a skinned mesh into a Skinner model.

A skinned mesh has to be converted into a Skinner model in advance to be used in the Skinner system. This can be done from the context menu; click a mesh asset to select it, then choose Skinner -> Convert Mesh from the right click menu.

Note that the mesh asset is usually located inside an fbx file. A few extra clicks are needed to select it. See the GIF below.

gif

Set up a character as usual.

Drag and drop a character prefab into the scene.

Attach a Skinner source to a skinned mesh renderer.

Add a Skinner source component to the game object that has a skinned mesh renderer component. Then set the Skinner model converted in the previous step to the model property.

screenshot

This Skinner source will override the skinned mesh renderer and then use it to convert vertex data. Note that this character will disappear from the scene, because it will be exclusively used for vertex conversion. If it has to stay visible, another instance of the same character should be added to the scene as a substitution.

Create a Skinner renderer object.

Create an empty game object and add one of the Skinner renderer components to it. Then set the source property in it to refer to the Skinner source object created in the previous step.

For starters, it's recommended to use the Skinner debug component that simply visualizes the vertex data provided from the source. If it shows nothing, there may be something wrong in the previous steps.

Skinner Renderer Components

Currently, the Skinner package provides four types of renderers.

Skinner Debug

gif

The Skinner debug renderer simply visualizes vertex data provided from a source.

This component doesn't need a template asset.

Skinner Glitch

gif

The Skinner glitch renderer draws triangles between randomly choosing vertices in a source. Although the number of triangles is fixed (21,845 triangles), triangles with long edges or a large area will be pulled out to maintain the silhouette. This behavior can be controlled by the threshold properties of the component.

This component doesn't need a template asset.

Skinner Particle

gif

The Skinner particle is a particle system that emits particles from vertices in a source. Several parameters (duration, rotation, etc) of each particle can be changed according to the speed of vertices, and thus it can be used to give some emphasis to character movement and trajectory.

The shapes of particles are defined in a Skinner particle template asset. Any shape can be used in a template, but it's recommended to use meshes with the very low poly count because the number of particle instances is determined from the number of vertices in the shapes (low poly == more particles!).

Skinner Trail

gif

The Skinner trail renderer draws trail lines from vertices in a source. The width of the lines can be changed according to the speed of vertices, and thus it can be used to give emphasis to movement too.

The length of the trail lines is pre-determined in a Skinner trail template asset. The number of lines is also pre-determined by its length. The longer the lines are, the fewer lines are drawn.

Compatibility

At the moment Skinner is only tested on Windows, macOS and iOS (metal). Possibly it runs on PS4 and Xboxone, but not sure about GLES3 and WebGL.

License

MIT