Giter Site home page Giter Site logo

pilat-bartosz / spritesheetrenderer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fabriziospadaro/spritesheetrenderer

0.0 0.0 0.0 1.81 MB

A powerful Unity ECS system to render massive numbers of animated sprites.

License: Other

C# 41.71% ShaderLab 51.26% HLSL 7.03%

spritesheetrenderer's Introduction

SpriteSheetRenderer

A powerful Unity ECS system to render massive numbers of animated sprites using DynamicBuffers and ComputeBuffer:

1 million animated sprites were rendered at 60fps on a Mid-2015 MacBook Pro.

N|Solid

C# 4 required

How to use (SINGLE INSTANTIATE):

  • 1- Create the Archetype:
EntityArchetype archetype = eManager.CreateArchetype(
    typeof(Position2D),
    typeof(Rotation2D),
    typeof(Scale),
    //required params
    typeof(SpriteIndex),
    typeof(SpriteSheetAnimation),
    typeof(SpriteSheetMaterial),
    typeof(SpriteSheetColor),
    typeof(SpriteMatrix),
    typeof(BufferHook)
);
  • 2- Record and bake this spritesheet(only once)
SpriteSheetManager.RecordSpriteSheet(sprites, "emoji");
  • 3- Populate components
List<IComponentData> components = new List<IComponentData> {
    new Position2D { Value = float2.zero },
    new Scale { Value = 15 },
    new SpriteIndex { Value = UnityEngine.Random.Range(0, maxSprites) },
    new SpriteSheetAnimation { maxSprites = maxSprites, play = true, repetition = SpriteSheetAnimation.RepetitionType.Loop, samples = 10 },
    new SpriteSheetColor { color = new float4(color.r, color.g, color.b, color.a) }
};
  • 4- Instantiate the entity
Entity e = SpriteSheetManager.Instantiate(archetype, components, "emoji");
  • Update the entity
Entity e = SpriteSheetManager.UpdateEntity(e, new Position2D { Value = float2.zero});
  • Destroy the entity
Entity e = SpriteSheetManager.DestroyEntity(e, "emoji");

How to use (BULK INSTANTIATE):

  • 1- Create the Archetype:
EntityArchetype archetype = eManager.CreateArchetype(
    typeof(Position2D),
    typeof(Rotation2D),
    typeof(Scale),
    //required params
    typeof(SpriteIndex),
    typeof(SpriteSheetAnimation),
    typeof(SpriteSheetMaterial),
    typeof(SpriteSheetColor),
    typeof(SpriteMatrix),
    typeof(BufferHook)
);
  • 2- Bulk instantiate entities
NativeArray<Entity> entities = new NativeArray<Entity>(spriteCount, Allocator.Temp);
eManager.CreateEntity(archetype, entities);
  • 2- Record and bake this spritesheet(only once)
SpriteSheetManager.RecordSpriteSheet(sprites, "emoji");
  • 3- Populate components
for(int i = 0; i < entities.Length; i++) {
  Entity e = entities[i];
  eManager.SetComponentData(e, new SpriteIndex { Value = 0});
  eManager.SetComponentData(e, new Scale { Value = 10 });
  eManager.SetComponentData(e, new Position2D { Value = RANDOM_VECTOR });
  eManager.SetComponentData(e, new SpriteSheetAnimation { maxSprites = MAX_SPRITES, play = true, repetition = SpriteSheetAnimation.RepetitionType.Loop, samples = 10 });
  SpriteSheetColor col = new SpriteSheetColor { color = A_COLOR };
  eManager.SetComponentData(e, col);
  eManager.SetComponentData(e, new BufferHook { bufferID = i, bufferEnityID = DynamicBufferManager.GetEntityBufferID(material) });
  eManager.SetSharedComponentData(e, material);
}

Support

SpriteSheetRenderer is an open-source project that I am developing in my free time. If you like it you can support me by donating.

Buy Me A Coffee: https://www.buymeacoffee.com/LRTk8rn

spritesheetrenderer's People

Contributors

fabriziospadaro avatar sarkahn 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.