Page 1 of 1
3D on the GPU [solved]
Posted: Mon Jul 01, 2024 5:49 am
by NoreoAlles
Hello, i wrote a little 3D Graphics renderer, which runs solely on the cpu and has "bad" performance because of that.
So now i want to take the triangles/vertecies ive parsed from an .obj and send it to a shader, aswell as a transformation matrix and rotation matrix, which both have to take the cpu-controlled camera position in account.
Can somebody give me a short intrudution, as to how i would start doing this?
I´ve read that
Shader:send can take both vertex an matrix informations, but dont you have to pass in multiple hundreds vertexes in the right order, as to have the GPU be used efficiantly? My source is in the attachments for clarification on what im trying to do (take my love:draw() code and multiplymatrixvector function and my matrices and make the GLSL equivalent run on the GPU)
Re: 3D on the GPU
Posted: Mon Jul 01, 2024 8:15 am
by marclurr
To use the GPU for rendering you don't really "send the vertices to a shader", the raw data is normally packed into a buffer that's run through the standard OpenGL pipeline, which will include usually at least 2 shaders, one vertex and one pixel/fragment shader. If you're not familiar with how OpenGL works it can be a bit to take in, but it's really not that complicated once you understand each step.
I'd recommend first having a read of this resource
https://learnopengl.com/ or try and find some YouTube video that explains OpenGL at a high level and then dig into the source code for the G3D library for Love which is very nicely written and shows how you can bend Love into rendering 3D.
https://github.com/groverburger/g3d
Or if you're just looking to get productive I'd say just have a play around with G3D and let it do the messy stuff.
Re: 3D on the GPU
Posted: Mon Jul 01, 2024 8:28 am
by NoreoAlles
I dont want to use g3d since, I´d much rather code an engine all by myself, where there are no "black boxes", i just can´t work with anything, where everything already has tons of variables which i dont need or understand, but i´ll take a look at the source, as you´ve suggested.
Re: 3D on the GPU
Posted: Thu Jul 11, 2024 4:59 pm
by Jasoco
I would still recommend g3d. It just provides the tools to easily do 3D. It isn't gonna replace your engine. You'll still need to create an engine. It's just more of a method for drawing stuff in 3D vs. Löve's normal built-in 2D drawing functions.
It's basically just:
Create a 3D object from a model.
Transform that 3D object to how you want it to display.
Draw that 3D object to the screen.
Basically the same as:
Load an image to use as a sprite or tile.
Choose where you want that image to show up and how you want it to show up.
Draw that 2D image to the screen.
Sure you can figure out how to do 3D yourself, but in the end you're just gonna end up doing what g3d already does. As soon as I discovered g3d I threw away all the hacks fake 3D methods I was using before. I had a raycaster I was working on. I had fake StarFox/old DOS 3D game style engines I was working on. Multiple versions of each. They became obsolete as soon as I switched.
Re: 3D on the GPU
Posted: Fri Jul 12, 2024 11:14 am
by NoreoAlles
Jasoco wrote: ↑Thu Jul 11, 2024 4:59 pm
I would still recommend g3d. It just provides the tools to easily do 3D. It isn't gonna replace your engine. You'll still need to create an engine. It's just more of a method for drawing stuff in 3D vs. Löve's normal built-in 2D drawing functions.
It's basically just:
Create a 3D object from a model.
Transform that 3D object to how you want it to display.
Draw that 3D object to the screen.
Basically the same as:
Load an image to use as a sprite or tile.
Choose where you want that image to show up and how you want it to show up.
Draw that 2D image to the screen.
Sure you can figure out how to do 3D yourself, but in the end you're just gonna end up doing what g3d already does. As soon as I discovered g3d I threw away all the hacks fake 3D methods I was using before. I had a raycaster I was working on. I had fake StarFox/old DOS 3D game style engines I was working on. Multiple versions of each. They became obsolete as soon as I switched.
I posted on the Games and Creations forum, i made a 3d engine with lighting myself, the only bit of code not diy is the parser, which i copied from g3d as i already wrote one and did not have the time to expand it for vertexnormals and the like.