Textured Polygons for All!

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Textured Polygons for All!

Post by Jasoco »

slime wrote:That example will have visual problems due to the lack of perspective-correct interpolation (because there is no real z-coordinate or 'perspective'.)

Image

I somewhat corrected for it manually (in that particular image's case with those particular coordinates, at least):

Code: Select all

{95, 95, 0.5, 0.5},
{0, 0, 0, 0},
{150, 30, 1, 0},
{225, 220, 1, 1},
{-20, 190, 0, 1},
{0, 0, 0, 0}
Image

You could probably do some trickery with hijacking the per-vertex color values to be a pseudo-z coordinate when used with a custom vertex shader that also has a custom perspective projection matrix, in order to get around the interpolation issues (it would probably be a less hack-ish way of doing 3D compared to straight Geometries, once you set it all up.) I am not sure whether you'd need a real depth buffer or not to do that, however.
I was just about to post about that. It kinda reminds me of the original PlayStation and the SuperFX chips which had horrible texture distortion. Which isn't necessarily a good thing. Is there a better way to correct this? I was hoping it would just be as simple as using PhotoShop's "Distort" function which created my example above. There was no 3D involved and it distorted perfectly the way it should have.
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Textured Polygons for All!

Post by slime »

To take advantage of hardware perspective correction, you'd need both a real z-coordinate for each vertex and a real perspective (rather than orthographic) projection matrix. Both of those can be done in 0.9.0 (albeit hackishly) with the vertex shader, but adding full non-shader support for either is not planned, since as far as I know there's no real benefit for 2D games.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Textured Polygons for All!

Post by Jasoco »

I can supply a "z" coordinate for each x and y if that's needed. How would I take advantage of that?

The library this thread is for is a little flakey on certain systems, sometimes looking completely wrong, plus it stops working if I resize the window and can't be used on canvases correctly. I was hoping to replace it with something a bit more official if possible.

3D effects can be very useful for many 2D games actually. Especially for effects and stuff.
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Textured Polygons for All!

Post by slime »

Jasoco wrote:I can supply a "z" coordinate for each x and y if that's needed. How would I take advantage of that?
Encode the z-coordinate in the 4 color components, and then decode it in a vertex shader. The shader would be something like this (keep in mind color components go from 0-1 in shaders):

Code: Select all

extern mat4 CustomPerspectiveMatrix;

float decodeZ(vec4 zcolor)
{
    ...
}

// mvp_ortho is the normal orthographic model-view-projection matrix, which isn't used here
vec4 position(mat4 mvp_ortho, vec4 vertex)
{
    // VertexColor is a variable provided by love to the vertex shader which gives the color at the vertex
    vertex.z = decodeZ(VertexColor);

    // create a new model-view-projection matrix; ModelViewMatrix is provided by love
    mat4 mvp = CustomPerspectiveMatrix * ModelViewMatrix;

    // transform the vertex by the custom matrix
    return mvp * vertex;
}
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Textured Polygons for All!

Post by Jasoco »

My brain doesn't really work tonight. What exactly would be returned from that pixelEffect code? A table that represents the geometry table?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Textured Polygons for All!

Post by bartbes »

Jasoco wrote:My brain doesn't really work tonight. What exactly would be returned from that pixelEffect code? A table that represents the geometry table?
It's a shader, not a pixeleffect, and they don't return anything, they handle the drawing. So the actual return value represents a single transformed vertex.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Textured Polygons for All!

Post by Jasoco »

Oh. Then how exactly would I dump it into my coding? If say I took points like this:

Code: Select all

{
    {0, 0, 0, 0},
    {200, -30, 1, 0},
    {200, 230, 1, 1},
    {0, 200, 0, 1},
}
Where the four points have a different distance from the camera, which I guess would represent their Z. Say the following values for each point: 100, 300, 300, 100
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Textured Polygons for All!

Post by Ref »

I'm afraid that Love 0.9 is just too fluid at this point for me to keep up with (when changes are made daily).
Will wait further coding until things stablize and an official release is made.
Will continue to monitor your work to get some insite as to how things work & what needs to be updated.
Best!

Edit: So couldn't resist! With the "old" version of Love 0.9, the conversion of my rotating textured cube was a snap.
Would post code but no assurance that "newer" versions of Love 0.9 would require furthe modifications.
Attachments
Rotatable textured cube using Love 0.9.0
Rotatable textured cube using Love 0.9.0
texturedCube.jpg (44.05 KiB) Viewed 9145 times
Last edited by Ref on Mon May 13, 2013 3:25 pm, edited 1 time in total.
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Textured Polygons for All!

Post by SiENcE »

So will LÖVE 0.9.0 include "Geometry-Shader"?
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Textured Polygons for All!

Post by slime »

SiENcE wrote:So will LÖVE 0.9.0 include "Geometry-Shader"?
Only if there's a really good reason to (so far I haven't found one).
Geometry shaders would add several complications to the shader pipeline, they're usually slower (and less useful) than tessellation shaders, they aren't supported on all systems, and I believe there are two separate distinct versions of them which might require separate shaders written for each.
Since they aren't actually very useful, it seems like a lot of hassle for no good reason to add proper support, if that's even possible.
Post Reply

Who is online

Users browsing this forum: No registered users and 40 guests