Textured Polygons for All!

Jasoco
Inner party member
Posts: 3641
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Textured Polygons for All!

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'.)

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}


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.

slime
Solid Snayke
Posts: 2814
Joined: Mon Aug 23, 2010 6:45 am
Contact:

Re: Textured Polygons for All!

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.

Jasoco
Inner party member
Posts: 3641
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Textured Polygons for All!

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.

slime
Solid Snayke
Posts: 2814
Joined: Mon Aug 23, 2010 6:45 am
Contact:

Re: Textured Polygons for All!

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;
}


Jasoco
Inner party member
Posts: 3641
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Textured Polygons for All!

My brain doesn't really work tonight. What exactly would be returned from that pixelEffect code? A table that represents the geometry table?

bartbes
Sex machine
Posts: 4944
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Textured Polygons for All!

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.

Jasoco
Inner party member
Posts: 3641
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Textured Polygons for All!

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

Ref
Party member
Posts: 677
Joined: Wed May 02, 2012 11:05 pm

Re: Textured Polygons for All!

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
texturedCube.jpg (44.05 KiB) Viewed 2964 times
Last edited by Ref on Mon May 13, 2013 3:25 pm, edited 1 time in total.

SiENcE
Party member
Posts: 771
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Textured Polygons for All!

So will LÖVE 0.9.0 include "Geometry-Shader"?

slime
Solid Snayke
Posts: 2814
Joined: Mon Aug 23, 2010 6:45 am