Entity highlighting in jobs : material UV / Atlas / Shader

This topic flies about in my mind for quite while now. But now decided to actually post a question.
I see few topics scattered around, reading changing UV, material, or mesh.
I may have missed something obvious, but so far, my research shows rather old results.

Currently for highlighting entities, I am using

ecb.SetSharedComponent <RenderMesh>

It works well in general, when highlighting and then returning color back to original.
Changing 1000 entities in a frame is not much of a big deal. Yet I don’t feel this is right approach to do highlighting. Also, this method is not as much flexible, as only limited by the predefined render meshes.

Now I would like scale this a bit up, by being able highlighting smoothly well over 1000 entities in a frame, without starting seeing significant spikes across threads. Is not something I want to do every frame. But just like selecting blocks / units.

That leads me to a question, that must be now more optimal way, to design highlight system. Either by UV changing for atlas texture, or shader color properties changing form a job.

Some older (2018) topics discusses vertices UV manipulations (by @tertle )
https://discussions.unity.com/t/710490/12

Another 2018 topics shows cool example, but I never had chance to get into much details

And I think there were few more relevant, but unable find atm.

Any thoughts and suggestions?

I know it is not really helpful, but I came across this the other day. I am quite interested in seeing how he went about it. Seems like it would be similar to what you are after as well.

2 Likes

This is cool finding.
In fact, I posted a question on the video comments.

Edit:
Another video of channel author Bosheng Li, indicates using
MaterialPropertyBlock
https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.html

Spiral Galaxy 70,000 stars generation, features review. [Unity ECS] ~110FPS

1 Like

Have you looked into DrawMeshInstancedIndirect.
To draw a massive amount of meshes and have control over color/uv or anything else you can think of on a per instance basis you must go this path.
It uses computer shaders so it means you will have write your own shader for that.

1 Like

Thx for an input. This gives a good direction, to the approach.

There are 2 ways I know of, both require a custom shader. The only problem is that you have to bypass the render system v2 and loose it’s functionality (culling, lod, etc)

Drawmeshinstanced - this uses material property block and therefore requires you to batch in 1023 “chunks” - it was compatible with render mesh v1 (so made sense at its time)

Drawmeshinstancedindirect, this has no batching requirements, but you have to bypass the render mesh v2

Hello!
I saw that my post was quoted, as far as I can remember I could achieve the color swapping by using material property blocks too, and I think my solution used DrawMeshInstanced (which was on the main thread).
I haven’t really followed up with new updates on the project, since I hit a roadblock trying to port an OOP library I wanted to use in the project library to be compatible with ecs, but couldn’t do it with my thinking back then.

I don’t know how much has changed in the DOTS eco system since I used it the last time, but from my prior experiences, you seem to be on the right track.
Good luck!

If I understood correctly, does that means loosing current DOTS, LOD and culling LOD and culling of DOTS?
If that is the case, this may rise a bit of concerns for my project need.
Not sure yet however.

Yes, that’s what I mean (with exception of loosing current DOTS - not sure what you meant by that)

It depends on your project if the trade off is worth it

My comma was most likely misplaced, introducing confusion of meaning.

I should rephrase
Loosing LOD and culling of DOTS. But not rather than for example LOD and culling of PyhsX, or otherwise Unity classical approach.

I just wanted 100% to ensure, that I follow correctly.

In meantime I just read regarding custom shader culling in,

Spiral Galaxy, CPU & GPU Frustum Culling. [Unity ECS]

1 Like

Here, we were toying with this a while back

1 Like

I typically find that CPU culling is usually cheaper than sending the unculled data to the GPU.

Perhaps 50,000 cars might toot you guys horn? lol. It gets a bit nuts (not that it isn’t already at 50) at 100k. 50k I guess isn’t that much compared to some of the other numbers you guys are throwing out there.

We using DMII for army units, cause of custom animation and other related stuff. And until unity release some customization for instances in RMv2 I suggest you write your render system on DMII, only for drawing. And when thing become, you’ll replace it’s easily.

2 Likes

I remember reading this thread back while. Then I thought I was following it, but apparently not :wink:
It has really good extensive content with code examples.
Thx for referencing it.

From the sngdan link, there are examples, of using shader as culling. Which may be something to consider?

Maybe I have missed response from that link, while reading through, but anyone knows, if Unity DOTS uses shader based, or some form of component based culling?

I was just wanting ask what is DMII, as search internet pointed me at diabetes (yeah not much Unity related :slight_smile: ).
Then I clicked and realized, you talking about
Graphics.DrawMeshInstancedIndirect

Funny to watch :slight_smile:
However, they got rather static texture. Can each car be of different colors?

This from Joachim is also a good reference - same concept with dmii

If my memory doesn’t faills me, I recall some discussion, or maybe Unite talk, which mentioned this approach, used in
Massive Battle in the Spellsouls Universe, to animate minions.

Joachim extracted it from Nordeus demo and a bit cleaned it.

I think in this talk briefly mentioning it
Unite Austin 2017 Keynote - Performance Demo ft. Nordeus [6/7]
(40k->100k minions)