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!
not correct texture cube
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
not correct texture cube
- Attachments
-
- point3.zip
- (952.56 KiB) Downloaded 89 times
Re: not correct texture cube
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:
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.
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.
Re: not correct texture cube
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!
Re: not correct texture cube
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.
Re: not correct texture cube
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!
Re: not correct texture cube
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.
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.
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: not correct texture cube
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.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.
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.
Re: not correct texture cube
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
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
Re: not correct texture cube
Thanks a lot, really helpful reply! Will look into this.Jasoco wrote: ↑Mon Jan 17, 2022 11:14 pmNow 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.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.
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.
Re: not correct texture cube
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.
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.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests