Shader send matrix

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
khofez
Prole
Posts: 12
Joined: Thu Dec 17, 2015 7:05 pm

Shader send matrix

Post by khofez »

I'd like to know if I could calculate somehow a perspective matrix, send it to the shader and calculate it together with the transform matrix and the vertex position, will I get a 3D camera??? is it possible??

For example:
(lua code)

Code: Select all

someShader:send( "perspectiveProj", perspectivematrix, ... )
(vertex shader)

Code: Select all

extern vec4 perspectiveProj;

vec4 position( mat4 transform_projection, vec4 vertex_position )
{
    return perspectiveProj * transform_projection * vertex_position;
}
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Shader send matrix

Post by Jasoco »

Oh, this is a topic that's been talked about way more than it should. It was done long ago...

viewtopic.php?f=5&t=12483&hilit=perspective

A user by the name of xXxMoNkEyMaNxXx (Creator of that topic) was inspired by a project (Star Fox style engine) I was working on at the time and took the initiative to create a shader himself. I still use it to this day. It has its problems but it does what it needs to. I've heavily modified the code numerous times to fit my needs.

3D in Löve is a well covered topic here.

Of course that only covers the texture warping.

Actually creating a 3D engine is a whole different beast. You encounter a whole new set of problems. First off you need to actually calculate a 3D point's 2D screen location. Then check to see which polygons are actually on screen and actually facing the camera. Then you run into the problem of Z-fighting since Löve isn't a 3D engine it doesn't do any per-pixel z-sorting.

Then a bunch of us have all made Wolfenstein style 3D engines.

However there is also another user who has created his own 3D engine called Löve3D.

Bottom line, 3D isn't something you can just jump into. You have to experiment. If you want to make a game in 3D as opposed to an engine so you can make a game, look into something like Unity since the 3D is done for you already.

Though making 3D work in something that's not meant for it is a sort of hobby for a lot of people... There's even 3D Pico8 games. Notably this one, which even I haven't been able to successfully dissect.
User avatar
slime
Solid Snayke
Posts: 3172
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Shader send matrix

Post by slime »

khofez wrote:I'd like to know if I could calculate somehow a perspective matrix, send it to the shader and calculate it together with the transform matrix and the vertex position, will I get a 3D camera??? is it possible??
Yes. You can send a matrix either as a nested table, or a flat table with dimension=4 also in it.

However you will not get the use of a depth buffer, backface culling, etc., unless you use a library for LOVE like this one, which exposes the native OpenGL functionality to use those: https://github.com/excessive/love3d

Keep in mind LOVE is a 2D framework, and while you can accomplish true hardware-accelerated 3D rendering in it, it's by no means designed for it.

Most of the "3D" forum posts from several years ago (monkeyman's included) don't really apply to LOVE as it is today, unless you really want to re-implement what the hardware and drivers and APIs already do for you.
Jasoco wrote:Actually creating a 3D engine is a whole different beast. You encounter a whole new set of problems. First off you need to actually calculate a 3D point's 2D screen location. Then check to see which polygons are actually on screen and actually facing the camera. Then you run into the problem of Z-fighting since Löve isn't a 3D engine it doesn't do any per-pixel z-sorting.
There's no need for any of that if you use shaders and https://github.com/excessive/love3d or similar, since they let you access the hardware and APIs that every other modern 3D game uses.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Shader send matrix

Post by Jasoco »

slime wrote:
Jasoco wrote:Actually creating a 3D engine is a whole different beast. You encounter a whole new set of problems. First off you need to actually calculate a 3D point's 2D screen location. Then check to see which polygons are actually on screen and actually facing the camera. Then you run into the problem of Z-fighting since Löve isn't a 3D engine it doesn't do any per-pixel z-sorting.
There's no need for any of that if you use shaders and https://github.com/excessive/love3d or similar, since they let you access the hardware and APIs that every other modern 3D game uses.
Where's the fun in that?
khofez
Prole
Posts: 12
Joined: Thu Dec 17, 2015 7:05 pm

Re: Shader send matrix

Post by khofez »

Thanks guys for answering. I just want a 3d engine cause I want to make a 2.5D game, i dont want to load any models or something, it will be just quads on the screen (textures, basically, of course it'd be polygons) , nothing less nothing more. And I dont want to fake it, I want to make a real perspective camera to use the Z axis. I know a lot of C++ and i have been looking into love's source code, i think i can make it happen but just for desktops, and since this is the only thing i want to release my game, i think i will try, but thanks!
khofez
Prole
Posts: 12
Joined: Thu Dec 17, 2015 7:05 pm

Re: Shader send matrix

Post by khofez »

BTW this forum is awesome! its very active! i dont have to wait an enternity to get an answer :D
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Shader send matrix

Post by zorg »

I don't have the quote with me at the moment, but i faintly remember at least one of the devs of Löve3D did state that they'd expect it to be used mostly for 2.5D effects. Like a 3D background for a bullet hell shooter, for example.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
khofez
Prole
Posts: 12
Joined: Thu Dec 17, 2015 7:05 pm

Re: Shader send matrix

Post by khofez »

Yea in the github repo on the README they said its mostly for 2.5D, but I think i'm going to make it directly on the C++ code
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests