Page 8 of 15

Re: Textured Polygons for All!

Posted: Tue Feb 12, 2013 5:13 pm
by Jasoco
vrld wrote:
Jasoco wrote:The reason OpenGL triangles work is because they're receiving XYZ coordinates.
Sorry, but this is not true. Texture has (almost) nothing to do with perspective.
In addition of screen coordinates, you provide texture coordinates that define how the texture is mapped onto the polygon.

Shameless plug: There is a good chance that there will be support for textured polygons in LÖVE 0.9.
Well, Mr. Smartypants. If I'd known that, I'd be coding in OpenGL. :P

I wish I could play with 0.9.0 now though. Any idea what year it might be coming out? :joker:

Haha, I'm in a sarcastic mood today. Must be the flu virus going through my head right now.

Re: Textured Polygons for All!

Posted: Wed Feb 13, 2013 2:26 pm
by Ref
xXxMoNkEyMaNxXx wrote:This is exactly what I was trying to say. How do you want me to implement it?
Sorry about previous response and delayed clarification but am busy getting ready for a trip.
Will try to describe what I would like by giving a simple example:
Take an equilateral triangle (tr1,tr2,tr3).
Take a piece of a texture (defined by tx1, tx2, tx3) that is exactly the same size and put it on the triangle.
Now distort the triangle my moving one or more of the vertices and have the same piece of texture (same vertices tx1, tx2, tx3) distort to fit the new shape (just like what happens with the textured quad but with one less point).

Re: Textured Polygons for All!

Posted: Wed Feb 13, 2013 2:53 pm
by slime
Jasoco wrote:I wish I could play with 0.9.0 now though. Any idea what year it might be coming out? :joker:
Hopefully next week.

I hope no one takes me seriously :O

Re: Textured Polygons for All!

Posted: Fri Feb 15, 2013 7:59 pm
by Jasoco
slime wrote:
Jasoco wrote:I wish I could play with 0.9.0 now though. Any idea what year it might be coming out? :joker:
Hopefully next week.

I hope no one takes me seriously :O
I want to take you seriously. But it's way too unbelievable. 0.8.1 would be only slightly more believable.

Re: Textured Polygons for All!

Posted: Fri Feb 15, 2013 10:06 pm
by slime
"Hopefully next week" in Valve Time is 9 months later, according to the wiki link. Maybe I should have said "today's update" instead. :P

In all seriousness though, you can try out what's currently in the 0.9.0 changes yourself by compiling the source code from the "minor" branch (or the "default" branch, which has many more changes including vertex shader support and doesn't break API compatibility yet).

The 'Geometry' textured polygon implementation hasn't been merged into the official LÖVE repository yet - you can get it here.

Re: Textured Polygons for All!

Posted: Fri Feb 15, 2013 10:12 pm
by Nixola
Heh, I think he knows

Re: Textured Polygons for All!

Posted: Fri Feb 15, 2013 10:36 pm
by Codex
I've been keeping my eye on this lib for an idea for a 3D game possibly. Something along the lines of a voxel cube based game, minecraft-like, but with a huge twist that I won't disclose just yet.

I read somewhere that to transverse the z-axis in lua hampers performance quite a bit, so I had an idea. Why not use a 2D array and store the z-axis information as a number?

IE.

z-axis is 10 cubes long. Let's say that you can only insert 3 different cube types. (air, dirt, grass) -- assuming a minecraft like example
air = 1,
dirt = 2,
grass = 3,

So at map[y][x] = num

Code: Select all

num = 1
  [x][y][1] = 1 -- air
  [x][y][2-10] = 1 -- rest of blocks are air 
num = 2
  [x][y][1] = 2 -- dirt
  [x][y][2-10] = 1 -- rest of blocks are air 
num = 3
  [x][y][1] = 3 -- grass
  [x][y][2-10] = 1 -- rest of blocks are air 
num = 4
  [x][y][1] = 1 -- air
  [x][y][2] = 2 -- dirt 
  [x][y][3-10] = 1 -- rest of blocks are air
num = 5
  [x][y][1] = 2 -- dirt
  [x][y][2] = 2 -- dirt
  [x][y][3-10] = 1 -- rest of blocks are air
num = 6
  [x][y][1] = 3 -- grass
  [x][y][2] = 2 -- dirt
  [x][y][3-10] = 1 -- rest of blocks are air
Hopefully you can see the pattern here.

so you have 59049 (3^10) range of possibilities. Insert some fancy math division to determine what block type on a z-axis location is, and whoolah!

Code: Select all

[x][y][1] = (num % 3) + 1
[x][y][2] = math.floor( (num % 9)/3) + 1
[x][y][3] = math.floor( (num % 81)/3) + 1
...

-- or this basically,

[x][y][z] = math.floor( (num % 3^z)/3) + 1   -- unless [z] = 1 then omit the math.floor part


I'm not sure if this would be any faster than just using a z-axis table to look up this information. The math algorithm you use to break up the z-axis can be localized (since it will be called repeatedly) and be a little faster. So the question comes down to which way is faster to access the Z-axis: looking up a third [z] axis table or using a bit of math on a 2D array to figure out your [z] info? Not sure how to test this... Also the number of block types and the size of the z-axis have a limit. (25 block types with a 10-size z-axis OR 5 block types with a 20-size z-axis --- approaches the Lua rounding error limit)

hmmm... on second thought if you turned into a string that limit would be MUCH bigger, but I imagine it would require more math.

:crazy:

Re: Textured Polygons for All!

Posted: Sat Feb 16, 2013 5:40 am
by xXxMoNkEyMaNxXx
I think that the most efficient way to store voxel data is in chunks. It does mean a 2D (or 3D, if you want infinite height) table of chunks, which are of course already 3D tables (but of constant size, so may be stored as a 1D table).

For clarification: by z-axis, do you mean up? It's always made more sense to me that up would be the y-axis. :brows:

Re: Textured Polygons for All!

Posted: Tue Mar 19, 2013 10:55 pm
by Ref
While waiting for xXxMonkEyMaNxXx to come up with textured triangles ... Ahm........

Re: Textured Polygons for All!

Posted: Wed Mar 20, 2013 5:32 pm
by Codex
xXxMoNkEyMaNxXx wrote:
For clarification: by z-axis, do you mean up? It's always made more sense to me that up would be the y-axis. :brows:
Yes I do mean up, but I've always thought "up" referenced in 3D as the z-axis was the standard.
Ref wrote:While waiting for xXxMonkEyMaNxXx to come up with textured triangles ... Ahm........
Nice! :ultrashocked: