Code Monkey home page Code Monkey logo

unity-ecs-instanced-sprite-renderer's Introduction

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.14f1 can be used to create a performant instanced sprite renderer. Find out about the new ECS in Unity here.

The assets used in the example are from Kenney's Animal Pack. Thanks to @Shinao for the help.

Quick Start

  1. Make sure you have this version of Unity 2018.1.0b12 installed
  2. Make sure the manifest.json file located at .../[PROJECT FOLDER]/Packages/manifest.json looks like this:
{
  "dependencies": {
      "com.unity.entities": "0.0.12-preview.19",
      "com.unity.package-manager-ui": "1.9.11",
      "com.unity.modules.ui": "1.0.0"
    },
    "testables": [
      "com.unity.collections",
      "com.unity.entities",
      "com.unity.jobs"
    ],
}
  1. Download this .unitypackage file and import it.
  2. Open SpriteRendererScene and press play.

How it Works

By adding SpriteInstanceRenderer to an entity it is rendered using its Position and Rotation 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.

Limitations

  • No way to push the matrices from a job
  • No NativeArray API, currently uses Matrix4x4[]

As a result this code is not yet jobified. For now, we have to copy our data into Matrix4x4[] with a specific upper limit of how many instances we can render in one batch.

unity-ecs-instanced-sprite-renderer's People

Contributors

paullj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.