Groverburger's 3D Engine (g3d) v1.5.2 Release

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
groverburger
Prole
Posts: 49
Joined: Tue Oct 30, 2018 9:27 pm

Re: Groverburger's 3D Engine (g3d) v1.5.1 Release

Post by groverburger »

Jasoco wrote: Tue Apr 05, 2022 10:00 pm
groverburger wrote: Mon Apr 04, 2022 6:57 pm Yep, the easiest way to achieve this is to change the camera's up vector, and make it point up and slightly to whatever direction you want to tilt.

Something like:

Code: Select all

g3d.camera.up = {some vector here}
g3d.camera.updateViewMatrix()
Interesting but it seems to rotate the world itself instead of just the camera. In other words, if I'm looking forward and I change say the Y value, it'll look right until I turn my head at which point I realize it's changing the world itself instead of just rolling the camera.

I tried to just use Löve's translation stuff like push, rotate, translate, pop to just rotate the image itself but of course since g3d is all shader based it just ignores all that. lol
The solution I found was to update the up vector every frame, and change it based on what direction the camera's looking. Otherwise it will just tilt in the same direction and not respect in what direction you're looking, which will feel like the world is tilted and not the camera.

Here's an example of what I would put in my update function:

Code: Select all

local direction, pitch = g3d.camera.getDirectionPitch()
local tilt = 0.05
local tiltDirection = direction + math.pi/2
g3d.camera.up = {math.cos(tiltDirection)*tilt*math.cos(pitch), math.sin(tiltDirection)*tilt*math.cos(pitch), 1}
g3d.camera.updateViewMatrix()
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Groverburger's 3D Engine (g3d) v1.5.1 Release

Post by Jasoco »

Yeah! That works well enough.

But I have a really stupid problem I've been trying to figure out for hours now relating to shaders.

Edit: I've posted my own thread for this question. A solution was found.
User avatar
groverburger
Prole
Posts: 49
Joined: Tue Oct 30, 2018 9:27 pm

Re: Groverburger's 3D Engine (g3d) v1.5.2 Release

Post by groverburger »

Hey everyone! The new release of g3d, 1.5.2 is out now!

The new changes are:
- Obj loading can now optionally flip the u and v coordinates when an obj file is loaded, which is useful when importing files from Blender
- Obj loading functionality is now available from the g3d namespace with g3d.loadObj(path, uFlip, vFlip) which returns a table that can be passed into g3d.newModel()
- Obj loading is now slightly more simple and efficient
- g3d's vector library is now available from the g3d namespace under g3d.vectors
- Updated the license to 2022
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Groverburger's 3D Engine (g3d) v1.5.2 Release

Post by Jasoco »

Out of curiosity, would writing an Ambient Occlusion shader be possible, if so would it be trivial, and if so would it work fast enough to not cause slowdown? Or should I not bother trying to write one? I feel like my game would look much better with subtle AO. In my old raycasting project I baked AO into the floor textures and it helped the look of the game a lot. But I'd love to do it myself. I just don't know where to start. I have been looking at tutorials online, but of course they're all meant for Unity and stuff like that so you have to try and translate it to how it would work in Löve.
User avatar
Hydrogen Maniac
Citizen
Posts: 80
Joined: Sat Dec 19, 2015 9:59 pm

Re: Groverburger's 3D Engine (g3d) v1.5.2 Release

Post by Hydrogen Maniac »

Jasoco wrote: Wed May 18, 2022 6:27 pm Out of curiosity, would writing an Ambient Occlusion shader be possible, if so would it be trivial, and if so would it work fast enough to not cause slowdown? Or should I not bother trying to write one? I feel like my game would look much better with subtle AO. In my old raycasting project I baked AO into the floor textures and it helped the look of the game a lot. But I'd love to do it myself. I just don't know where to start. I have been looking at tutorials online, but of course they're all meant for Unity and stuff like that so you have to try and translate it to how it would work in Löve.
I've been trying to figure this out too and while I never managed to wrap my head around some of the pure glsl tutorials out there for things like SSAO, I did come up with this solution for my not-quite-voxel game.
Untitled.png
Untitled.png (666.08 KiB) Viewed 14492 times
Since the game you showed off earlier used voxel terrain maybe some of this will translate, all you really need in your shader code is a function that takes a position as an argument and returns a boolean depending on whether or not the position is inside the terrain.

My ao implementation works by darkening each pixel based on the shortest distance to any adjacent surface. The grid like nature of the world makes finding this distance fairly straight forward since you only really need to check in 8 directions and finding the distance between a point and a grid line in a cardinal direction just boils down to getting the decimals of either the X,Y or Z component and finding the position of a corner of a given grid cell just requires you to floor the position vector.

A simpler solution would be to sample random points around each fragment and darken each pixel a little for every sample which lands inside an occluded part of the map. This will however produce some pretty noisy results and is generally less performant, although the noisiness could in theory be reduced by blurring the result but I never got around to that. Glsl doesn't have any noise functions built in but there are plenty of simple implementations out there, just know that most user made noise functions tend to have some quirks. The screenshot below is from an earlier version of the project which used this sort of ao.
Untitled2.png
Untitled2.png (324.42 KiB) Viewed 14492 times
I also found this article about ao in minecraft like worlds which might be of interest. I don't think the default g3d shader supports vertex colors so you might have to implement that on your own if this method interests you.

I hope this was of some help :)
I'm way too sober for this...
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Groverburger's 3D Engine (g3d) v1.5.2 Release

Post by Jasoco »

Hydrogen Maniac wrote: Thu May 19, 2022 12:11 pm
Jasoco wrote: Wed May 18, 2022 6:27 pm Out of curiosity, would writing an Ambient Occlusion shader be possible, if so would it be trivial, and if so would it work fast enough to not cause slowdown? Or should I not bother trying to write one? I feel like my game would look much better with subtle AO. In my old raycasting project I baked AO into the floor textures and it helped the look of the game a lot. But I'd love to do it myself. I just don't know where to start. I have been looking at tutorials online, but of course they're all meant for Unity and stuff like that so you have to try and translate it to how it would work in Löve.
I've been trying to figure this out too and while I never managed to wrap my head around some of the pure glsl tutorials out there for things like SSAO, I did come up with this solution for my not-quite-voxel game.

Untitled.png

Since the game you showed off earlier used voxel terrain maybe some of this will translate, all you really need in your shader code is a function that takes a position as an argument and returns a boolean depending on whether or not the position is inside the terrain.

My ao implementation works by darkening each pixel based on the shortest distance to any adjacent surface. The grid like nature of the world makes finding this distance fairly straight forward since you only really need to check in 8 directions and finding the distance between a point and a grid line in a cardinal direction just boils down to getting the decimals of either the X,Y or Z component and finding the position of a corner of a given grid cell just requires you to floor the position vector.

A simpler solution would be to sample random points around each fragment and darken each pixel a little for every sample which lands inside an occluded part of the map. This will however produce some pretty noisy results and is generally less performant, although the noisiness could in theory be reduced by blurring the result but I never got around to that. Glsl doesn't have any noise functions built in but there are plenty of simple implementations out there, just know that most user made noise functions tend to have some quirks. The screenshot below is from an earlier version of the project which used this sort of ao.

Untitled2.png

I also found this article about ao in minecraft like worlds which might be of interest. I don't think the default g3d shader supports vertex colors so you might have to implement that on your own if this method interests you.

I hope this was of some help :)
THat's really cool. Do you have any example code you wrote I can look at and get an idea where to start? I'm still learning the ins and outs of shaders and it's amazing what can be done.
Raph
Prole
Posts: 4
Joined: Sun Jul 24, 2022 5:41 am

Re: Groverburger's 3D Engine (g3d) v1.5.2 Release

Post by Raph »

Does g3d support animations?
LucidPolygon
Prole
Posts: 1
Joined: Mon Aug 01, 2022 11:29 pm

Re: Groverburger's 3D Engine (g3d) v1.5.2 Release

Post by LucidPolygon »

Hey (whoever responds) Im having a weird issue,

Im not totally sure why but my test model unloads when I use love.window.setMode to change the resolution, the weirder part is it doesnt unload the 'background' model, only the scene model.
screenshotItem.png
screenshotItem.png (150.6 KiB) Viewed 12677 times
User avatar
pbmn
Prole
Posts: 19
Joined: Sat Oct 24, 2020 12:15 pm

Re: Groverburger's 3D Engine (g3d) v1.5.2 Release

Post by pbmn »

So I'm making a 3D 3rd person camera movement with player tracking functionality and player control with G3D and it's going very well! Loved the engine!
Just now finished making the Groveburger's 3d-fps level 100% playable in 3rd person. I'd love to make this cam lib available soon! I only need to make it smoother and have more camera options, like changing to first person and wall/occlusion detection adjustments.

I think this may help future projects as well :D

But does anyone here knows how to make billboarding for sprites in g3d? I'm thinking of making animated 2D sprites for the player running/idle/jumping...

Image
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Groverburger's 3D Engine (g3d) v1.5.2 Release

Post by Jasoco »

LucidPolygon wrote: Tue Aug 02, 2022 8:11 pm Hey (whoever responds) Im having a weird issue,

Im not totally sure why but my test model unloads when I use love.window.setMode to change the resolution, the weirder part is it doesnt unload the 'background' model, only the scene model.

screenshotItem.png
I don't see anything wrong with the code. Can you post a .love file that shows the problem instead?
pbmn wrote: Mon Aug 15, 2022 6:57 pm So I'm making a 3D 3rd person camera movement with player tracking functionality and player control with G3D and it's going very well! Loved the engine!
Just now finished making the Groveburger's 3d-fps level 100% playable in 3rd person. I'd love to make this cam lib available soon! I only need to make it smoother and have more camera options, like changing to first person and wall/occlusion detection adjustments.

I think this may help future projects as well :D

But does anyone here knows how to make billboarding for sprites in g3d? I'm thinking of making animated 2D sprites for the player running/idle/jumping...

Image
Billboarding basically means taking a flat textured polygon and rotating it to always face the camera. So you can do it one of two ways. Either rotate the sprite object in the Lua code or I believe you can use a vertex shader to rotate it as well. Some of the projects that use g3d do this. Look at their code and get some ideas. Off the top of my head, Leadhaul uses 2D sprites with a billboard shader IIRC.
Raph wrote: Tue Jul 26, 2022 1:08 pm Does g3d support animations?
What kind of animations? Texture animation or model animation? For the first one, you can update the texture of a model every frame to change its texture for animations. For the second, look into the Hoarder's Horrible House of Stuff project. I believe it uses bones in its models to animate the main character. If I'm not mistaken.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot] and 2 guests