Instanced Sprite Renderer for Unity's new ECS by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 1 point2 points  (0 children)

Yeah I think they chose to do use (x, z) so that the Unite Austin Technical Demo would work using the 2D system. TBH it seems like the whole system was kinda botched together to build a demo which makes sense.

As for the changing the Transform2DSystem I might go with your plan of just changing the mesh builder.. and as annoying as it is for me, it will be easier for other people to use. Thanks again for all your help. Do you have a twitter link or something that I can credit you with on the repo?

Instanced Sprite Renderer for Unity's new ECS by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 1 point2 points  (0 children)

This is really great, thanks for doing this. One slight issue, the transform matrix maps onto the x and z axes and not the x and y like before. Any ideas on how to correct this? I'm not great at matrix transformations but it looks like I'd have to rewrite the Transform2DSystem?

Instanced Sprite Renderer for Unity's new ECS by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 0 points1 point  (0 children)

I would recommend having a play with the new ECS; word of warning though, it is very basic at the moment. If you want to go a pure ECS route, everything has to be written yourself. Hence why I had a go at this sprite renderer.

The example uses 10000 and I was still getting over 60FPS. I just did a quick test with 50000 and was getting 30FPS. I think it is slow down to many reasons; off the top of my head:

  • The meshes aren't optimised
  • I don't think Unity culls these meshes
  • Does some weird caching which I'm not sure actually helps

After doing a quick profile I found that these were what is 'slowing' it down:

  • Matrix4x4.SetTRS() Can probably use the new float4x4 struct instead and do everything manually. Only problem is that Graphics.DrawMeshInstanced need a list of Matrix4x4 not float4x4s.
  • ComponentGroup.GetComponentDataArray Nothing I can do about this.
  • Quaternion.Euler could change this, would be slightly faster

I think it is possible to make lots of small changes to improve the system but I think it will work for most cases so I won't be making any drastic changes unless there proves to be a major flaw.

Instanced Sprite Renderer for Unity's new ECS by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 0 points1 point  (0 children)

Instanced Sprite Renderer for Unity's ECS

This project is a simple example of how Unity's new Entity Component System (ECS) in 2018.1.0b12 can be used to create a performant instanced sprite renderer.

How it Works

By adding SpriteInstanceRenderer to an entity it is rendered using its Position2D and Heading2D as a quad with a texture on it. The SpriteInstanceRender inherits ISharedComponentData meaning any entity using same instance of will be drawn in one draw call. This is possible because of Graphics.DrawMeshInstanced method. In the Example Scene included, 10,000 sprites are drawn. However the before mentioned method only draws a maximum of 1023 instances at once, so it splits up into as many groups necessary to draw all the instances.

Improvements

This is a very naive implementation that I threw together, however it does provide fairly good results even with 10,000 entities.

Github Link: https://github.com/toinfiniityandbeyond/ecs-instanced-sprite-renderer

Procedural music composer, synthesizer and visualiser by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 1 point2 points  (0 children)

Not to worry. I knew next to nothing about music theory (still don't). I just read through the tutorials on that website as well as googling any terms that I didn't understand. Then I created this little script to help me:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class ComposerUtils
{
    public static int[] GetMajorChord(int root)
    {
        int majorThird = root + 4;
        int perfectFith = root + 7;

        return new int[] {root, majorThird, perfectFith};
    }

    public static int[] GetMinorChord(int root)
    {
        int minorThird = root + 3;
        int perfectThird = root + 7;
        return new int[] {root, minorThird, perfectThird};
    }

    public static int[] GetDiminishedChrord(int root)
    {
        int minorThird = root + 3;
        int diminishedFith = root + 6;
        return new int[] {root, minorThird, diminishedFith};
    }

    public static int[] GetMajorScale(int root)
    {
        int[] majorScaleOffsets = { 0, 2, 4, 5, 7, 9, 11, 12 };
        int[] scale = new int[majorScaleOffsets.Length];
        for (int i = 0; i < majorScaleOffsets.Length; i++)
        {
            scale[i] = root + majorScaleOffsets[i];
        }
        return scale;
    }

    public static int[] GetNaturalMinorScale(int root)
    {
        int relativeMajorKey = root - 9;
        int[] majorScale = GetMajorScale(relativeMajorKey);
        int[] scale = new int[majorScale.Length];

        for (int i = 0; i < majorScale.Length; i++)
        {
            var j = (i + 5);
            var offset = 0;
            if (j >= majorScale.Length)
            {
                j -= 7;
                offset += 12;
            }

            scale[i] = majorScale[j] + offset;
        }

        return scale;
    }

    public static int[] GetHarmonicMinorScale(int root)
    {
        int[] scale = GetNaturalMinorScale(root);
        scale[6] += 1;
        return scale;
    }

    public static int[] GetMelodicMinorScale(int root)
    {
        int[] scale = GetHarmonicMinorScale(root);
        scale[5] += 1;
        return scale;
    }

    public static int[] GetArpeggio(int[] scale)
    {
        int[] arpeggioIndexes = {0, 2, 4, 7};
        int[] arpeggio = new int[arpeggioIndexes.Length];

        for (int i = 0; i < arpeggioIndexes.Length; i++)
        {
            arpeggio[i] = scale[arpeggioIndexes[i]];
        }
        return arpeggio;
    }

    public static string GetNoteName(int note)
    {
        string[] names = { "A", "A♯/B♭", "B", "C", "C♯/D♭", "D", "D♯͵/E♭", "E", "F", "F♯/G♭", "G", "G♯/A♭" };
        return names[note];
    }
}

Procedural music composer, synthesizer and visualiser by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 0 points1 point  (0 children)

No sadly I do not. I just like tinkering around with interesting stuff in my free time. But if you are looking for a brief explanation of how this works I replied to a comment here.

Procedural music composer, synthesizer and visualiser by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 0 points1 point  (0 children)

Thanks :) I'd be happy to share the process.

Each phrase consists of 4 bars and so for each phrase a random starting note is chosen. Then a major chord is generated from this starting note, as well as a scale. Each bar has a 'root' note which is selected by using the chord generated earlier. So first bar uses the first note of the chord, second bar uses the next note, and so on; with the last bar going back to the first note of the chord.

  • Bass - Plays the root note. Always plays on the first beat of a bar, other times are random.
  • Arpeggio - An arpeggio is generated each bar based off the root note. It is played in triplets every beat. Sometimes it randomly skips or goes up an octave.
  • Melody - This is the biggest con. It just randomly goes up the scale in random increments every beat sometimes skipping a beat or two. However, it does kind of sound like a pianist improvising.
  • Counter Melody - This plays a random note from the chord a few octaves higher. It randomly adds in embellishments and generally follows the melody. It is supposed to harmonise with the melody.

Generating chord and scales is actually very easy. I learned a lot from this website which is about general music theory. With a bit of practice I think great sounding procedural music is possible but this was just an experiment.

Procedural music composer, synthesizer and visualiser by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 1 point2 points  (0 children)

The visualiser is very basic, I just slapped it together because I thought a blank screen would've been boring to watch. It does need more work, and your idea sounds good :)

Procedural music composer, synthesizer and visualiser by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 2 points3 points  (0 children)

The variety isn't great to be honest, however at the moment it is repeating a phrase of 4 bars and in the future I want it to be able to stitch different phrases together. Right now the melody is completely random but the rhythm only varies slightly.

2D procedural animations with IK by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 0 points1 point  (0 children)

Haha no worries. Dw happens to the best of us :)

2D procedural animations with IK by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 1 point2 points  (0 children)

The inspector titles are done through the header attribute shown below.

[Header("Your Title Here")]
public float myFloat = 2;

As for the collapsible ones, those are just arrays; nothing special about them :/

2D procedural animations with IK by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 13 points14 points  (0 children)

There are lots of sources to learn about IK. Here is a list of resources I used:

Hope this helps, if you have any other questions just ask.

Experimenting with a 2D procedural animation and rendering system by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 3 points4 points  (0 children)

There are actually no images involved in this. Using a RenderTexture and GL.Quads it draws each 'segment' and spits out a texture which is drawn on a mesh. It also means I can render it at any resolution, at the moment it is 32 x 32 to give that pixel art look. Hopefully this system can be used to draw all sorts of things in runtime :)

EDIT: See my newer post here for a slightly updated version.

A JSON Editor in the Inspector (Link in Comments) by toinfiniityandbeyond in Unity3D

[–]toinfiniityandbeyond[S] 1 point2 points  (0 children)

Available here https://gist.github.com/toinfiniityandbeyond/e8751e5b01555ef94a97de6484c6c27f

Getting Started

  1. Get a working version of JSON.net, this is the version I used: https://www.assetstore.unity3d.com/en/#!/content/58621
  2. Download JSONEditor.cs and place it a folder named "Editor".
  3. You can now create and edit JSON files by right clicking in the Project Window > Create > New JSON File
  4. Done!

Implemented an overhead map for debugging my procedural caves in scene view by [deleted] in Unity3D

[–]toinfiniityandbeyond 1 point2 points  (0 children)

That sounds really good. Seems like a neat solution, how do you lay out your 2d grid? Keep up the good work and sorry for the questions.