SpriteBatch:attachAttribute() and geometry instancing [SOLVED]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
cval
Citizen
Posts: 58
Joined: Sun Apr 20, 2014 2:15 pm
Location: Ukraine

SpriteBatch:attachAttribute() and geometry instancing [SOLVED]

Post by cval »

I'm currently excited about SpriteBatch:attachAttribute function and i'm trying to mock-up some kind of silly mesh instancing based on that function. Now, while attaching VertexColor attribute works completely as i was expecting (i created helper class which allows me to change colors of already existing sprites, for example), i cannot get my head on VertexPosition and VertexTexCoord (sprites become heavily distorted due to wrong vertex attributes).
From what i understand, SpriteBatch itself works as big mesh, but i'm not sure what math should i use to modify VertexPosition and VertexTexCoord.
However, i do get that each time we add new quad or sprite to spritebatch its vertex texture coordinates are calculated based from quad viewport (something like UV = TextureSize/QuadViewportSize ?).
I also would like to know how SpriteBatch mesh works, which mesh type is it (in terms of LOVE mesh type constants), what vertex order each sprite has, or if i ask wrong questions about wrong things.

And yes, i do want to refrain from vertex shader magic for what i want to do.
I saw NoGame screen of 0.10.1 and i can tell that mosaic sprite tinting can be achieved with attachAttribute, but i've tried too look at source code of that screen and found no usage of said function =(

Sorry if i wasn't able to make a clear point, but i'm really interested in how all this work and i think it can be useful to someone else here.
sprbatch_vertattr.love
(10.08 KiB) Downloaded 80 times
Edit:
I think i've got vertex order, so now i should be able to calculate UV coordinates properly, but i'm still stuck with vertex position transformations with rotation and skew because of my lack of CGI math knowledge
poly.png
poly.png (4.19 KiB) Viewed 1832 times
Last edited by cval on Wed Apr 27, 2016 7:59 pm, edited 2 times in total.
cval
Citizen
Posts: 58
Joined: Sun Apr 20, 2014 2:15 pm
Location: Ukraine

Re: SpriteBatch:attachAttribute() and geometry instancing

Post by cval »

I think i actually made it to work the way i want. However shearing is still unavailable, but feel free to modify code to add shear transormation - i personally have never used it.

Previously i've been asked about why i need anything like that (geometry instancing) in LÖVE, here is an example video:
https://www.youtube.com/watch?v=ySB7Rqo ... e=youtu.be

Those white webbings are actually sprites in the spritebatch, however without geometry instancing or vertex shader magic i couldn't do fade-in of each independent sprite like that. Other way to achieve that is to draw each web segment independently with their own transparency values, but obviously, that is not the most optimal way to draw tons of same sprites.
And yes, those connected with joints to simulate chain-like behavior.
sprbatch_vertattr.love
(10.08 KiB) Downloaded 107 times
The only problem right now is to deal with situations when SpriteBatch sprite count reaches its buffer limit. In vanilla SpriteBatch you could just set new buffer size, hovewer here i'm forced to recreate internal mesh so that it's vertex count match required SpriteBatch buffer size in order to attachAttribute function to work.
cval
Citizen
Posts: 58
Joined: Sun Apr 20, 2014 2:15 pm
Location: Ukraine

Re: SpriteBatch:attachAttribute() and geometry instancing

Post by cval »

Have you ever thought about bringing your sprite to front or to back relatively to another sprite? Well, now you can.
In the example below, when you use function swapSpriteGeometry() you can switch two sprites with each other and it will bring one to front and one to back without re-creating them.
love 2016-04-27 02-02-19-04.gif
love 2016-04-27 02-02-19-04.gif (65.81 KiB) Viewed 1774 times
sprbatch_vertattr.love
(10.19 KiB) Downloaded 91 times
I think this is going to be last bump of this thread, since i no longer seek help on this matter, can i ask moderator to move thread to appropriate board? Like, "projects and demos" maybe?
Post Reply

Who is online

Users browsing this forum: YaCy [Bot] and 3 guests