Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Polygon Sprites

Author
Message
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Jan 2019 13:50 Edited at: 3rd Jan 2019 13:51
Hi all,
Just started working on something to create triangular sprites using no media. I am thinking it could be useful for a simple graphic style game. You can give it 3 points (x,y), single colour or two for gradient sprites (gradient goes top to bottom) and it will create a sprite with a correct shape and image centred on the centre point of the triangle.
Here's an example of what can be produced:

Using AppGameKit V2 Tier 1

Attachments

Login to view attachments
fubarpk
Moderator
14
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 3rd Jan 2019 14:09
very cool baxslash
fubar
chafari
Valued Member
12
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 3rd Jan 2019 15:24
That looks great baxslash...I'm glad to see you around here.
I'm not a grumpy grandpa
janbo
10
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 3rd Jan 2019 16:16
Uhh that brings my very fist post to my mind as I still thought 2D shadows without shaders would be a good idea
I made an triangle filling algorithm which divides the triangle in a flat top and flat bottom triangle to draw it easily.

Again a very clever approach
Now make functions to create not a triangle but a real polygon with more than 3 vertices
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Jan 2019 11:10
Thanks guys, nice to see you too chafari!
janbo, your shadow system looks really cool. Looks like it works in a very similar way. Making polygons would be pretty simple as the way I'm calculating these shapes is just using GetSpriteHit pixel by pixel so any convex shape should work. Would just take a little change to the system
Using AppGameKit V2 Tier 1
Phaelax
DBPro Master
15
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Jan 2019 17:33
Could this be adapted to make quads? And if so how fast could it work if I was to manipulate the corners in real time? Basically I've been wanting a typical rectangular sprite but with the ability to move the 4 corners individually.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
janbo
10
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 8th Jan 2019 18:08 Edited at: 8th Jan 2019 18:09
@Phaelax
Are you asking for creating 3D objects using that collision trick ? which wont work as you don't draw lines but position vertices in the first place.
Or 3D planes pretending to be 2D sprites, which is very possible with just an orthographic projection matrix, you would be able to stretch and compress your "sprites"

Oh wrote this and then read your post again which made me realize you DO mean the second method
You could also use LoadShader, pass AGK's default sprite vertex shader to it and alter the original sprite vertices in the shader.
fubarpk
Moderator
14
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Adelaide
Posted: 8th Jan 2019 18:14
Quote: "You could also use LoadShader, pass AGK's default sprite vertex shader to it and alter the original sprite vertices in the shader."

That sounds clever are you perhaps planning a 2D Shader library
fubar
janbo
10
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 8th Jan 2019 19:04 Edited at: 8th Jan 2019 19:18
Planning ... hm I'm actually planning to do it for some time now, but please don't have hight hopes
It's all in my head and a bit of code already.
But I have too many plans, for the 3D shader pack still, for games, for arduino and RPI projects and then besides my full time job I have to sleep sometimes
Buuut I guess it's the same for you guys too, so actually I should be motivated to get started

Please post any further stuff relating to my shader pack here to not hijack this thread more
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Jan 2019 10:57
Quote: "Could this be adapted to make quads?"

For sure you could adapt it to do that but shaders would be easier. I was thinking it might not be too hard to use psuedo 2D objects (actually 3D meshes) like Unity uses but shaders would likely be quicker to create, easier to use and faster to run.
Using AppGameKit V2 Tier 1
Bengismo
1
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 10th Jan 2019 12:01 Edited at: 10th Jan 2019 12:04
I wrote a shader to allow for individual control of the 4 corner positions of a sprite some time back. Its the stock standard sprite pixel shader and a custom vertex shader to move the 4 corners to wherever you would want

The vertex shader is this:


It works fine and allows you to set the 4 coords
SetShaderConstantArrayByName(qshad,"Coords",0,0,0,0,0) // Top left
SetShaderConstantArrayByName(qshad,"Coords",1,0,100,0,0) // bottom left
SetShaderConstantArrayByName(qshad,"Coords",2,100,0,0,0) // Top right
SetShaderConstantArrayByName(qshad,"Coords",3,100,100,0,0) // bottom right


However..... this almost always does NOT have the effect you think it will!!

If you just want a solid fill color it works fine, but if you use a texture then it ends up looking quite distorted. This is due to the quad being made of two triangles which then are stretched and so UV's are linearly interpreted

As an example of a texture on a custom quad ill attach the image below


So as nice as it sounds it probably not REALLY what you want. There is a way to coorect this by mapping UV's to the new quad which I can post up but it makes the vertex shader a fair bit harder to understand.

I've also got a working version which allows any number of triangles to be added to "virtual" sprite with texture mapping etc... So you could have a sprite made of say 5 triangles but then the collision shape for this becomes horrendous and doesnt fit so it tends to make much more sense to make it out of multiple sprites anyway (unless your not worried about collisions or physics).
puzzler2018
User Banned
Posted: 10th Jan 2019 12:57
That's very useful to know - Thanks @Bengismo
Phaelax
DBPro Master
15
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Jan 2019 16:12
Only problem with that I see the texture isn't evenly distributed among the vertices. You can clearly see how nothing is distorted in the first triangle
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Bengismo
1
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 10th Jan 2019 16:16 Edited at: 10th Jan 2019 16:19
Quote: "Only problem with that I see the texture isn't evenly distributed among the vertices. You can clearly see how nothing is distorted in the first triangle"


That's what I was saying in the post above! The first triangle doesnt appear distorted because it has a 90 corner. When you start moving vertices you have to move to quadrilateral interpolation of UV's. Its doable but the shader is just more complex to correct UV coords.

http://reedbeta.com/blog/quadrilateral-interpolation-part-2/

Login to post a reply

Server time is: 2019-03-23 20:14:36
Your offset time is: 2019-03-23 20:14:36