Page 1 of 15

Textured Polygons for All!

Posted: Sun Jan 20, 2013 7:44 am
by xXxMoNkEyMaNxXx
*It should actually be called textured quadrilaterals, but that's irrelevant.
*You need a GPU that supports pixel effects.
Perspective.lua
The only required file. V8 require'Perspective'
(4.62 KiB) Downloaded 1529 times
After hours of thinking and math, here's what everyone's been waiting for!

Usage:

Code: Select all

local texture=require'Perspective'
function love.draw()
	texture.quad(image,vertex1,vertex2,vertex3,vertex4)
end
Updates:
v2
-Fixed image being rotated one quarter turn ccw.
v3
-Added parallel edge support.
v4
-If image is nil, no image will be drawn.
-If only the vertices are given (e.g. texture.quad(v1,v2,v3,v4) ) the function will behave properly.
v5
-Added tiled textures, see Demo's source code.
v6
-Fixed repeat options to work like expected
-Many small tweaks
v7
-Assume edges are parallel if it's close, otherwise the math would degrade.
-Clear effect after writing image
v8
-Change scaling to image-based instead of polygon-based (More intuitive)

Known issues:
-Does not display properly when using love's built in push and pop stuffs.

I'm so excited to see what people will make with this! :awesome:

Also, please tell me what I should do so you can be comfortable using it straight out of the box.

Controls for Demo:
Click and drag the corners of the image.
Demo v8.love
Try uncommenting in main.lua!
(207 KiB) Downloaded 1583 times

Re: Textured Polygons for All!

Posted: Sun Jan 20, 2013 1:06 pm
by Darky
not " for All! "
Image

Re: Textured Polygons for All!

Posted: Sun Jan 20, 2013 2:31 pm
by IndieKid
That is just what I need!

Re: Textured Polygons for All!

Posted: Sun Jan 20, 2013 6:10 pm
by xXxMoNkEyMaNxXx
Lol, sorry Darky. Consider finding or getting a machine or GPU that supports pixel effects, the potential is simply amazing.

Re: Textured Polygons for All!

Posted: Sun Jan 20, 2013 6:14 pm
by Ref
Question!
Why is the texture rotated 90 degrees counter clockwise?

Re: Textured Polygons for All!

Posted: Sun Jan 20, 2013 6:18 pm
by xXxMoNkEyMaNxXx
Ah, I've fixed it.

At least it wasn't mirrored :L
My excuse: The test image was rotationally symmetrical!

Re: Textured Polygons for All!

Posted: Sun Jan 20, 2013 8:18 pm
by Ref
Trying to get your code into a form that I'm comfortable using - so please forgive mess I've made of your code.
It seems that your effect is not too robust for certain geometries.
(I did add someting to keep boundaries from being parallel but still had problems.)
If you have the time, I'd like to know what I'm doing wrong.

Re: Textured Polygons for All!

Posted: Mon Jan 21, 2013 1:14 am
by xXxMoNkEyMaNxXx
Oh dear... I'll just add parallel edge support to GLSL. XD I was planning on doing it anyway.
It seems that your effect is not too robust for certain geometries.
Which part are you talking about?

Re: Textured Polygons for All!

Posted: Mon Jan 21, 2013 3:06 am
by Jasoco
This could be the greatest thing I have ever asked for. I am going to try and implement this into my game tonight and post the results. Oh boy.

I think Ref was talking about how the points can't go concave or else the image warps to unrecognizable. Which is fine for me. I am curious why Ref's demo has a rotating image that distorts if it's not at a 90º angle.

Re: Textured Polygons for All!

Posted: Mon Jan 21, 2013 3:13 am
by scutheotaku
I don't have much else to say except - excellent work!!!