Other

项目介绍

Antoshidza/NSprites 是一个托管在 GitHub 上的开源项目,主要使用 C# 编写,采用 Other 许可证,目前获得 661 个 Star、59 次 Fork。

仓库全名
Antoshidza/NSprites
开源许可证
Other
Star 数
661
Fork 数
59
未关闭 Issue
1

README 摘要

NSprites - Unity DOTS Sprite Rendering Package This framework provides sprite rendering system compatible with Entities package (unity ECS). Changelog Basically it sync whatever entity component you want with GPU data to perform instanced rendering. As a result all entities with same Material can be rendered with single drawcall. Features Using power of :boom:DOTS:boom: + instancing to render numerous of sprites…

完整内容见 GitHub 原始 README 或本页 。

常见问题

NSprites 用什么语言开发?

主要使用 C# 编写,采用 Other 许可证,目前有 661 个 Star。

NSprites 可以免费商用吗?

仓库标注的许可证为 Other,商用前请先阅读仓库 LICENSE 文件确认授权范围。

如何获取 NSprites 的源码?

可以直接克隆仓库:git clone https://github.com/Antoshidza/NSprites.git,默认分支为 main;安装与运行步骤见仓库 README。

NSprites 最近还在维护吗?

仓库最近一次更新为 2025年6月3日,当前有 1 个未关闭 Issue;Star 数为 661,可作为社区活跃度的参考。

关于

Unity DOTS Sprite Rendering Package

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
794
价值分
415
活跃状态
活跃

语言占比

C#

README

NSprites - Unity DOTS Sprite Rendering Package

This framework provides sprite rendering system compatible with Entities package (unity ECS). Changelog

Basically it sync whatever entity component you want with GPU data to perform instanced rendering. As a result all entities with same Material can be rendered with single drawcall.

Features

  • Using power of :boom:DOTS:boom: + instancing to render numerous of sprites
  • Using any public to you per-entity blittable component as shader instanced property
  • Data update strategies to avoid unnecessary CPU load
  • Edit-time rendering (subscene only)

Basic API

For more detailed information please read project’s wiki :blue_book:

// registrate components as properties at assembly level anywhere in project
[assembly: InstancedPropertyComponent(typeof(WorldPosition2D), "_pos2D")]
[assembly: InstancedPropertyComponent(typeof(SpriteColor), "_color")]
// registrate render with ID, Material, capacity data and set of properties
if (!SystemAPI.ManagedAPI.TryGetSingleton<RenderArchetypeStorage>(out var renderArchetypeStorage))
    return;
// don't registrate same renderID
renderArchetypeStorage.RegisterRender
(
    renderID,
    material,   // material with [Enable GPU Instancing] enabled and shader supporting instancing
    bounds      // bounds in which sprites will be visible. For example new Bounds(Vector3.zero, Vector3.one * float.MaxValue)
    null,       // override for MaterialPropertyBlock if needed
    128,        // initial ComputeBuffers capacity
    128,        // minimal capacity step for ComputeBuffers
    "_pos2D",   // world 2D position property
    "_color"    // color property
);
// initialize sprite entity with all needed components for rendering
entityManager.AddSpriteRenderComponents(spriteEntity, renderID);
// WorldPosition2D and SpriteColor are example client's components
entityManager.AddComponentData(spriteEntity, new WorldPosition2D { Value = /*your value here*/ });          
entityManager.AddComponentData(spriteEntity, new SpriteColor { Value = Color.White });

// or from baker
private class Baker : Baker<SpriteAuthoring>
{
    public override void Bake(SpriteAuthoring authoring)
    {
        AddComponent(new WorldPosition2D { Value = new float2(authoring.transform.position.x, authoring.transform.position.y) });
        AddComponent(new SpriteColor { Value = Color.White });
        this.AddSpriteComponents(authoring.RenderID); // Render ID is client defined unique per-render archetype int. You can define it manually or for example use Material's instance ID or whatever else.
    }
}

Also shader you’re using should be compatible with instancing. Check my example shader gist. The main idea is to use StructuredBuffer<T> _propertyName. Though it is possible to use instanced properties with ShaderGraph, so you may try your option. For local example shader main part can look like:

// ...
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
StructuredBuffer<int> _propertyPointers;
StructuredBuffer<float4> _color;
#endif
// ...
Varyings UnlitVertex(Attributes attributes, uint instanceID : SV_InstanceID)
{
    // ...    
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
    int propPointer = _propertyPointers[instanceID]; // this is internal package property to point right data during component sync
    float4 color = _color[propPointer];
#else
    //fallback if somehow instancing failed
    float4 color = float4(1,1,1,1);
#endif
    // ...
}

How it works

SpriteRenderingSystem sync registered entity components with ComputeBuffers to send data to GPU and then renders entities with Graphics.DrawMeshInstancedProcedural. System also controls how ComputeBuffers reallocates if capacity exceeds. Sprites are simple entities with no limits of what components you use.

Check Foundation

NSprites doesn’t provide anything except rendering and managing data for it. Though you can implement anything you want on top of it. Also I want to share some foundation project where you can find examples and maybe even useful tools to work with this package. Foundation provides such things as sorting / culling / animation / 2D transforms / basic data authoring and registration.

Check sample project - Age of Sprites

This sample project covers basics of rendering with NSprites. Use it to get a main idea of how stuff can be implemented but not as production-ready solutions.

RomeGIf

Games created with NSprites

Reconquista

Installation

Requirements

  • Unity 2022.2+
  • Entities v1.0.0-pre.65+

Compatibility

There is few things we should care when talking about using NSprites in real projects. Since this package uses GPU instancing and ComputeBuffer on CPU side with StructuredBuffer<T> on GPU side (in shader) to send sprites data, we need platform and Graphics API support this two.

Graphics API Description
Direct3D11 :warning: partially supported
Direct3D12 :white_check_mark: supported
Vulkan :white_check_mark: supported
OpenGLCore :warning: partially supported
OpenGLES3 :warning: partially supported
Platform Description
PC :white_check_mark: supported
WebGL :no_entry: unsupported
Android :grey_question: not fully checked
iOS :question: not checked

Install via Package Manager

  • Window -> Package Manager -> + button -> Add package from git url
  • Paste https://github.com/Antoshidza/NSprites.git

Install via git submodule

Support :+1: Contribute :computer: Contact :speech_balloon:

I wish this project will be helpful for any ECS early adopters! So feel free to send bug reports / pull requests, start discussions / critique, those all are highly appreciated! You can contact with my discord account / join discord server! Also there is a thread on unity dots forum!

Preferred way to send support: BOOSTY

"Buy Me A Coffee"

评论

暂无评论