Segments
Line renderer for DOTS tech stack.
Install / Use
/learn @andrew-raphael-lukasik/SegmentsREADME
Segments
Segments is a lightweight line renderer for DOTS tech stack.
- You create and then fill the
Segmentbuffer (pairs of points) plotting shapes you want,SegmentUpdateSystemthen pushes this data to the GPU wheregeometry shadercreates output triangles on screen. Segmentbuffer's lifetime control and plotting, being part of anEntity, can happen either in a system, job, editor window or a monobehaviour - your choice.- Can be used for runtime shapes only or in the editor for debug gizmos as well.
- To develop the look of the lines to your specific needs you are expected to know shader programming basics to be able to fork and modify the base shader on your own
Getting started:
Here is a minimum code that will draw lines on screen:
Entity _segments;
void OnEnable () => Segments.Core.Create(out _segments);// creates an Entity that will hold all the vertex data and will be responsible for drawing them
void OnDisable () => Segments.Core.Destroy(_segments);// destroys the entity and all data associated with it
void Update ()
{
Segments.Segment segment = Segments.Core.GetSegment(_segments);
NativeList<float3x2> buffer = segment.Buffer;
buffer.Length = 3;
Vector3 pos = transform.position;
buffer[0] = new float3x2( pos , pos+transform.right );
buffer[1] = new float3x2( pos , pos+transform.up );
buffer[2] = new float3x2( pos , pos+transform.forward );
Segments.Core.SetSegmentChanged(_segments);
}
Code above is just an illustration of the workflow to get you started. The best way of doing this is with use of job system as these will result in the best performance. Look into Samples to learn more.
Performance
Stress tested with 300k segments on my laptop (i7-7700HQ, GTX1060M) and bottleneck turned out to be the GPU (shader).
RenderDoc debugger shows that stress test scene generates very high amount of PS invocations (at 1920x876 res). I thought about maybe adding depth-only prepass to reduce this but that would require changes to URP renderer which is something I don't find fitting for this project - I want it to be plug&play, with minimum dependencies.
<img height="300" alt="image" src="https://github.com/user-attachments/assets/c6b02d4f-1620-4708-a37f-56171a2e56c2" />I'm investigating whenever replacing geometry shader with a compute shader will reduce the GPU time.
Also, this exact test scene is provided as one of the samples so you can test it yourself.
Samples
-
stress test
<img height="300" alt="image" src="https://github.com/user-attachments/assets/8ab05960-c7dc-420b-9300-fadd06554574" /> -
mesh wireframe
<img height="300" alt="image" src="https://github.com/user-attachments/assets/b401f24c-e612-4d2e-9640-27e0b330f982" /> -
drawing mesh bounding boxes
<img height="300" alt="image" src="https://github.com/user-attachments/assets/3ee90180-6176-469c-8cea-ffa49bd41c76" />
Requirements
- Unity 6000.0
- URP (not tested with HDRP yet)
Installation Unity 6000.x
Add this line in manifest.json / dependencies:
"com.andrewraphaellukasik.segments": "https://github.com/andrew-raphael-lukasik/segments.git#upm",
Or via Package Manager / Add package from git URL:
https://github.com/andrew-raphael-lukasik/segments.git#upm
Related Skills
node-connect
347.6kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.6kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.6kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
