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

Showcase your libraries, tools and other projects that help your fellow love users.
Nelvin
Party member
Posts: 124
Joined: Mon Sep 12, 2016 7:52 am
Location: Germany

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

Post by Nelvin »

That's because of the depth buffer - the frontmost tree is rendered before the obscured behind it and, even for fully transparent pixels, depth value is written to the depth buffer. Pixels rendered behind that tree, even in the transparent area, will be discarded based on their depth.

What you need for the trees is a shader discarding full transparent pixels.
https://www.khronos.org/opengl/wiki/Tra ... cy_Sorting
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

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

Post by Jasoco »

Nelvin wrote: Tue Dec 14, 2021 2:00 pm That's because of the depth buffer - the frontmost tree is rendered before the obscured behind it and, even for fully transparent pixels, depth value is written to the depth buffer. Pixels rendered behind that tree, even in the transparent area, will be discarded based on their depth.

What you need for the trees is a shader discarding full transparent pixels.
https://www.khronos.org/opengl/wiki/Tra ... cy_Sorting
I had a feeling it was something that simple. But is there an easy way I can either modify the g3d shader or implement a simple shader like this? I need to read that post above too. I’m sure it has some useful information. I just don’t know the proper way to stack shaders for use with this library. Like I said I already had that simple fog shader but as soon as I tried to add another shader it broke. So I’m sure there’s a proper way to have them all work together. Seeing as I’ve looked at those other projects and a bunch of them have multiple shaders at once.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

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

Post by grump »

Jasoco wrote: Tue Dec 14, 2021 6:09 pm So I’m sure there’s a proper way to have them all work together. Seeing as I’ve looked at those other projects and a bunch of them have multiple shaders at once.
Not really. You can either do multiple passes. That may be difficult to do with this "engine", idk. Or you can factor multiple shaders into functions and combine their results.

Learning GLSL basics is required to be able to get the desired results. The language is simple, there's plenty of tutorials out there, and they are easily adapted to LÖVE. Start with 2D effects. 3D stuff typically requires multiple buffers and the learning curve is steeper.
User avatar
Froyok
Prole
Posts: 27
Joined: Tue Nov 16, 2021 4:53 pm
Contact:

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

Post by Froyok »

Given your art style, wouldn't a simple "discard" in the pixel shader be enough to avoid writing over objects behind ? (alpha test kind if transparency)
Nelvin
Party member
Posts: 124
Joined: Mon Sep 12, 2016 7:52 am
Location: Germany

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

Post by Nelvin »

Jasoco wrote: Tue Dec 14, 2021 6:09 pm
Nelvin wrote: Tue Dec 14, 2021 2:00 pm That's because of the depth buffer - the frontmost tree is rendered before the obscured behind it and, even for fully transparent pixels, depth value is written to the depth buffer. Pixels rendered behind that tree, even in the transparent area, will be discarded based on their depth.

What you need for the trees is a shader discarding full transparent pixels.
https://www.khronos.org/opengl/wiki/Tra ... cy_Sorting
I had a feeling it was something that simple. But is there an easy way I can either modify the g3d shader or implement a simple shader like this? I need to read that post above too. I’m sure it has some useful information. I just don’t know the proper way to stack shaders for use with this library. Like I said I already had that simple fog shader but as soon as I tried to add another shader it broke. So I’m sure there’s a proper way to have them all work together. Seeing as I’ve looked at those other projects and a bunch of them have multiple shaders at once.
Sadly I don't have any experience using this engine - I just use discard in pixelshaders for some depth sorting/batching of sprites based on the alpha value of the pixels. Once you know how to use different shaders it's really easy to fix your problem.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

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

Post by Jasoco »

Froyok wrote: Tue Dec 14, 2021 10:06 pm Given your art style, wouldn't a simple "discard" in the pixel shader be enough to avoid writing over objects behind ? (alpha test kind if transparency)
It definitely would. I just don't know where to put that code properly. Seems like it would be the easiest thing to implement. Since it's basically just running the pixel color through a filter to check the alpha before sending it out to the renderer.

Edit: Well it was easier than I thought. I just added the appropriate "if pixel alpha is less than half then discard" code to the fog shader I already had and it did the job. It'll do for now until I get a better lighting system.
Nelvin wrote: Wed Dec 15, 2021 12:30 am Sadly I don't have any experience using this engine - I just use discard in pixelshaders for some depth sorting/batching of sprites based on the alpha value of the pixels. Once you know how to use different shaders it's really easy to fix your problem.
Really I just want simple shadows and simple lighting. Possibly also light sources but with a central ambient "sunlight/moonlight". Also a simple water shader that just puts foam around the edges of "ground" areas. Not looking for raytracing or anything crazy like that. If I could figure out how to use the techniques from Hoarder and the Flamerunner games as they both have pretty much all the stuff I'd want. So I know g3d is capable of doing what I want. It's just that everyone is so much smarter than I am. lol

Unfortunately it's not as simple as just copying the code and files over because Flamerunner was made before g3d and Hoarder is a heavily modified really early version of g3d which has changed a lot since then. So it'll take a bit more understanding of what does what.
User avatar
groverburger
Prole
Posts: 49
Joined: Tue Oct 30, 2018 9:27 pm

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

Post by groverburger »

Jasoco wrote: Wed Dec 15, 2021 2:08 am Really I just want simple shadows and simple lighting. Possibly also light sources but with a central ambient "sunlight/moonlight". Also a simple water shader that just puts foam around the edges of "ground" areas. Not looking for raytracing or anything crazy like that. If I could figure out how to use the techniques from Hoarder and the Flamerunner games as they both have pretty much all the stuff I'd want. So I know g3d is capable of doing what I want. It's just that everyone is so much smarter than I am. lol

Unfortunately it's not as simple as just copying the code and files over because Flamerunner was made before g3d and Hoarder is a heavily modified really early version of g3d which has changed a lot since then. So it'll take a bit more understanding of what does what.
Just pushed a new release version of g3d and updated the g3d wiki.

Maybe this post can help you out with writing shaders for g3d?


Note: I got rid of the need to manually update the view and projection matrices for custom shaders in version 1.5.1 - updating all of the necessary variables now happens automatically in Model:draw()
User avatar
Jasoco
Inner party member
Posts: 3725
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, I'm slowly teaching myself how shaders work. It's a lot to take in as I've never really been able to fully understand how languages work except for the easier more "basic" languages like BASIC and Lua. I was able to merge the "fog" shader someone wrote a while ago to do distance fog and a bit of the code 4aiman made for their lighting demo to use the normal shading technique so flat textures don't look the same on every side rather they shade themselves based on the direction they're facing. It makes my project look better than vanilla g3d does and I'm glad this stuff is possible.

I have a question though, is it possible at all to do backface culling only on certain models? I've looked at the Wiki and it doesn't seem so. There's just a single love.graphics.setMeshCullMode() callback, but I don't see any Model:setMeshCullMode() feature. It seems to be an all or nothing type of thing. Is this just a limitation of Löve or is this something you can't do in 3D rendering at all? To get around it for now I just set it to backfire culling and for polygons where I want them to be two sided I just create a second polygon flipped around the other way with a flipped texture normal. But it'd be nice if I could just turn it off for specific models when I need to.
User avatar
Hydrogen Maniac
Citizen
Posts: 79
Joined: Sat Dec 19, 2015 9:59 pm

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

Post by Hydrogen Maniac »

Jasoco wrote: Mon Jan 17, 2022 6:45 pm I have a question though, is it possible at all to do backface culling only on certain models? I've looked at the Wiki and it doesn't seem so. There's just a single love.graphics.setMeshCullMode() callback, but I don't see any Model:setMeshCullMode() feature. It seems to be an all or nothing type of thing. Is this just a limitation of Löve or is this something you can't do in 3D rendering at all? To get around it for now I just set it to backfire culling and for polygons where I want them to be two sided I just create a second polygon flipped around the other way with a flipped texture normal. But it'd be nice if I could just turn it off for specific models when I need to.
You can simply call love.graphics.setMeshCullMode between drawing the models.

Code: Select all

love.graphics.setMeshCullMode("back")
model:draw()	--drawn with back culling

love.graphics.setMeshCullMode("front")
model2:draw()	--drawn with front culling
I'm way too sober for this...
User avatar
Jasoco
Inner party member
Posts: 3725
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 »

Hydrogen Maniac wrote: Mon Jan 17, 2022 11:36 pm You can simply call love.graphics.setMeshCullMode between drawing the models.

Code: Select all

love.graphics.setMeshCullMode("back")
model:draw()	--drawn with back culling

love.graphics.setMeshCullMode("front")
model2:draw()	--drawn with front culling
Why didn't I think of that? Does it have any sort of impact on performance?
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests