not correct texture cube

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

not correct texture cube

Post by stepps »

I am not sure what is either missing or wrong for this textured cube to be warped like that,
what do I need to modify to make it look correct?

Keep in mind I want to use purely CPU side, so no GPU shaders, etc (if possible)

Thanks!
Attachments
point3.zip
(952.56 KiB) Downloaded 74 times
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: not correct texture cube

Post by pgimeno »

What's missing is perspective-correct texturing; when the two triangles of each face get deformed without perspective correction, they look warped, like in the "Affine" sample in this image:
Image

Too hard to solve with no GPU help. You could try to minimize the effect by subdividing each face into more squares; as you apply perspective correction to each vertex within the subdivided face, most things will go to place, but it's not going to be 100% correct.

Depending on what you plan to do with it, there might be other solutions, like using raycasting techniques, and if you give in to using the GPU, check also https://love2d.org/forums/viewtopic.php?f=5&t=92376. But if you are going to have polygons in arbitrary orientation and not just horizontal planes and vertical planes, you're going to need to go for a GPU-based 3D solution.
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

Re: not correct texture cube

Post by stepps »

Hmm, I understand. So assuming I want like you say arbitrary orientation of polygons on GPU, what would I need to do with my code, would it require tons of changes or just some? Thanks!
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: not correct texture cube

Post by pgimeno »

Probably tons. You would make the cube be a mesh but with 3D vertices. You need to define a custom vertex layout in order to be able to use Z, as Löve's default is to provide just X, Y. You need a vertex shader which should include: a model matrix to place the model in any position/orientation, a view matrix for your camera, and a projection matrix for perspective projection. And if you want to handle lighting, you also need an adequate fragment shader. Or you can use a 3D engine such as Groveburger's 3D engine (see the Libraries and Tools forum, it's usually in the first few pages) to not have to worry about all these things.
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

Re: not correct texture cube

Post by stepps »

I saw some of those 3D libraries, but I kinda want to try doing it myself a bit. But let's say for now, just to fix the texture warping itself with GPU, no lighting or camera, just the texture, is that just a matter of perspective matrix on GPU alone or something else. Thanks for the help so far, appreciate it!
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: not correct texture cube

Post by grump »

Come on man. That's way beyond a support question, that's at least a whole year in school learning linear algebra question.

There's an endless stream of tutorials for 3D programming out there: in formats for people who can read, or in YouTube format for people who can't read.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: not correct texture cube

Post by Jasoco »

grump wrote: Mon Jan 17, 2022 10:48 pm Come on man. That's way beyond a support question, that's at least a whole year in school learning linear algebra question.

There's an endless stream of tutorials for 3D programming out there: in formats for people who can read, or in YouTube format for people who can't read.
Now let's not be too harsh. I literally asked this same question like a decade ago. Someone wrote a library for me to do textured polygons that I was still using up until a couple months ago when I started using g3d.

Here's that library if the OP is interested. But I do recommend looking into g3d instead because it's just so simple to use as long as you have a means to make .obj files to use in it. If you ask me, that's the harder part of it all. Learning how to use Blender or Crocotile. Also you'll have to learn shaders eventually if you want to do stuff like lighting effects. g3d will be much faster for one reason. With the perspective library, you need to call a shader for every single polygon you want to make. But with g3d you only call shaders for every model. So if you put a lot into a single model then there's less shader calls.

That said, if you want textures to look right, you'll have to use a shader.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: not correct texture cube

Post by grump »

Yeah I get it, it might seem harsh.

It's just not a question that can be sufficiently answered in a comment, unless "use this black box" is an acceptable answer. It doesn't seem to be a reasonable request for support.

http://www.catb.org/~esr/faqs/smart-questions.html
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

Re: not correct texture cube

Post by stepps »

Jasoco wrote: Mon Jan 17, 2022 11:14 pm
grump wrote: Mon Jan 17, 2022 10:48 pm Come on man. That's way beyond a support question, that's at least a whole year in school learning linear algebra question.

There's an endless stream of tutorials for 3D programming out there: in formats for people who can read, or in YouTube format for people who can't read.
Now let's not be too harsh. I literally asked this same question like a decade ago. Someone wrote a library for me to do textured polygons that I was still using up until a couple months ago when I started using g3d.

Here's that library if the OP is interested. But I do recommend looking into g3d instead because it's just so simple to use as long as you have a means to make .obj files to use in it. If you ask me, that's the harder part of it all. Learning how to use Blender or Crocotile. Also you'll have to learn shaders eventually if you want to do stuff like lighting effects. g3d will be much faster for one reason. With the perspective library, you need to call a shader for every single polygon you want to make. But with g3d you only call shaders for every model. So if you put a lot into a single model then there's less shader calls.

That said, if you want textures to look right, you'll have to use a shader.
Thanks a lot, really helpful reply! Will look into this.
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: not correct texture cube

Post by pgimeno »

Yes, that does perspective correct rendering, at the expense of sucking a lot of GPU resources. You can't have many such polygons on the screen at once, at least with my graphics card, or that's my recollection when I tested it.

If you know the concepts of model matrix, view matrix and perspective matrix, and know how to generate them, then by all means go for it yourself. I can point you to a thread where I give an example of a very basic 3D engine, one that I wrote with the purpose of showing how to do basic 3D with Löve, that you can check to get the idea of how it works (it doesn't have a model matrix IIRC). If you don't know these concepts, you may need to give up on the "I want to do everything myself" and go for a canned solution like g3d.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 14 guests