Shader sprite global to local

#1

Any way to convert global position in sprite shader to local?

Or maybe local position of sprite to global?

I tryed it with world matrix.
But it looks like sprites get mat4(1) as world matrix. So i can’t use it.

0 Likes

#2

There currently is no good way to do that.
One could do it like this and make the calculation yourself in the vertex shader.

What do you want it for? Perhaps there’s a another way of solving it?

1 Like

#3

For now I set position of sprite center as shader uniform. But if I can do it in shader it will be better.

Why? You set world matrix for models. Why not set it for sprites?

0 Likes

#4

Why? You set model matrix for models. Why not set it for sprites?

It will render every single sprite in a separate draw call. We’ve preferred batching of sprites for performance reasons. Models tend to have far more vertices, and the benefit of batching doesn’t apply there.

From your other post:

I can’t use sprite.set_constant(). Because it will be break batching.

Your feature request would break batching too.

Sometimes we add a first version of a feature, but not to a 100% to at least get some of our users unblocked. We haven’t painted ourselves into a corner, we can add to the feature later.
In this case, I don’t think we thought anyone would actually want it on sprites .
Adding it to sprites will of course increase the engine size (unclear by how much), for a feature that is currently more of an “idea” as you put it in the other post.

I actually think the current way of setting the material constant is a valid approach given the current circumstances.

2 Likes

#5

Thanks for your explanation.
I don’t know gapi.
But I always think that setting world matrix not break batching. It is not same as setting position in shader? Every sprite have different position and it not break batching?

0 Likes

#6

I understand that it is not blocking and needed for small amount for people.
But in some cases it can be usefull. Like skew sprite or billboard shader.

Please think about it=)



5 Likes

#7

I think you make a good case for it! I like it!

We will definitely think about it.

3 Likes