Sorry to double-post but can you help me figure out how to implement this into my game? I'm not sure where to put the code and how to load it so it works with g3d. This is exactly what I need right now as one of the many people now trying to make 3d games in Löve.veethree wrote: ↑Tue Sep 28, 2021 9:33 am There is. Conveniently i was just in the process of figuring this out for my game
fog.gif
Before i continue i want to get across that i'm not a huge shader guy, So there might be many things wrong with this. Maybe someone can check my work here.
You need to write a custom shader to achieve this. Here's what i came up with:`player` is the position of the player (or camera), `fog_min` & `fog_max` is the minumum & maximum distance of the fog and `fog_color` is the fogs color.Code: Select all
varying vec4 worldPosition; extern vec3 player; extern number fog_min; extern number fog_max; extern vec4 fog_color; vec4 effect(vec4 color, Image tex, vec2 tc, vec2 sc) { vec4 pixel = Texel(tex, tc); number d = distance(player, vec3(worldPosition[0], worldPosition[1], worldPosition[2])); number amount = smoothstep(fog_min, fog_max, d); return mix(pixel, fog_color, amount); }
Then you use this, along with g3d's standard vertex shader to render your models. I found that for whatever reason, If i just passed my shader to the draw function of models it wasn't working, So i ended up just replacing g3d.shader in init.lua with my own shader.
EDIT: Changed the shader to have a min & max amount for the fog.
Groverburger's 3D Engine (g3d) v1.5.2 Release
- 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.4 Release
Re: Groverburger's 3D Engine (g3d) v1.4 Release
Sure, Keep in mind, I'm still not a shader guyJasoco wrote: ↑Fri Oct 22, 2021 11:52 pmSorry to double-post but can you help me figure out how to implement this into my game? I'm not sure where to put the code and how to load it so it works with g3d. This is exactly what I need right now as one of the many people now trying to make 3d games in Löve.veethree wrote: ↑Tue Sep 28, 2021 9:33 am There is. Conveniently i was just in the process of figuring this out for my game
fog.gif
Before i continue i want to get across that i'm not a huge shader guy, So there might be many things wrong with this. Maybe someone can check my work here.
You need to write a custom shader to achieve this. Here's what i came up with:`player` is the position of the player (or camera), `fog_min` & `fog_max` is the minumum & maximum distance of the fog and `fog_color` is the fogs color.Code: Select all
varying vec4 worldPosition; extern vec3 player; extern number fog_min; extern number fog_max; extern vec4 fog_color; vec4 effect(vec4 color, Image tex, vec2 tc, vec2 sc) { vec4 pixel = Texel(tex, tc); number d = distance(player, vec3(worldPosition[0], worldPosition[1], worldPosition[2])); number amount = smoothstep(fog_min, fog_max, d); return mix(pixel, fog_color, amount); }
Then you use this, along with g3d's standard vertex shader to render your models. I found that for whatever reason, If i just passed my shader to the draw function of models it wasn't working, So i ended up just replacing g3d.shader in init.lua with my own shader.
EDIT: Changed the shader to have a min & max amount for the fog.
First, Define that shader somewhere, I'm sure you don't need help with that part.
The model:draw() function in g3d is supposed to be able to take a shader as an argument, But i didn't have much success with that. So i slightly altered the shader definition in init.lua in g3d.
Code: Select all
g3d.shader = love.graphics.newShader(g3d.shaderpath, your_shader_here)
- 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.4 Release
Oh wow it works! Thanks for the reply. I'll have to play around and see what I can do with shaders and g3d.veethree wrote: ↑Sat Oct 23, 2021 7:59 am Sure, Keep in mind, I'm still not a shader guy
First, Define that shader somewhere, I'm sure you don't need help with that part.
The model:draw() function in g3d is supposed to be able to take a shader as an argument, But i didn't have much success with that. So i slightly altered the shader definition in init.lua in g3d.
After that just send it the appropriate externs and it should work. I believe the externs to be quite self explanatory, Except maybe the "player" vec3 which i should have definitely named "camera".Code: Select all
g3d.shader = love.graphics.newShader(g3d.shaderpath, your_shader_here)
I wonder if there's also a way to use the normals of the triangles to shade them depending on the direction they're facing so I don't have to create a texture atlas with separate normal and darker versions of every texture.
Re: Groverburger's 3D Engine (g3d) v1.4 Release
For sure, g3ds vertex shader gives you access to everything you need. I managed to implement some basic lighting based on this tutorialI wonder if there's also a way to use the normals of the triangles to shade them depending on the direction they're facing so I don't have to create a texture atlas with separate normal and darker versions of every texture.
- 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.4 Release
I saw Groverburger's Flamerunner does lighting too. I have a lot to learn and I'm really excited. I was getting tired of fumbling around with a slow raycaster. As neat as it looks now.
- groverburger
- Prole
- Posts: 49
- Joined: Tue Oct 30, 2018 9:27 pm
Re: Groverburger's 3D Engine (g3d) v1.4 Release
If you have any more details about what didn't work for you, I'd be interested to hear it. Here's how I intended shaders to work and how I use them in my projects. I'll demonstrate with a shader that renders vertex normals. Hopefully this will be useful to other people too.
I define a "normal.frag" file somewhere in my project which contains the following GLSL:
Code: Select all
varying vec3 vertexNormal;
vec4 effect(vec4 color, Image tex, vec2 texcoord, vec2 pixcoord) {
return vec4(vertexNormal.xyz, 1);
}
Then when I go to define a model that uses this shader, I do something like this:
Code: Select all
model = g3d.newModel("model.obj", "modelTexture.png")
modelShader = love.graphics.newShader(g3d.path .. "/g3d.vert", "normal.frag")
Now when I go to render the model in my love.draw function I do this:
Code: Select all
g3d.camera.updateProjectionMatrix(modelShader)
g3d.camera.updateViewMatrix(modelShader)
model:draw(modelShader)
I've made a few fragment and vertex shaders that people will probably find useful (like billboarding around arbitrary axes, etc.) over the time I've been working on g3d and my own personal projects. If people are interested I can bundle 'em up and share 'em.
Re: Groverburger's 3D Engine (g3d) v1.4 Release
Oh. It’s been a while since I messed around with this, but I’m pretty sure I didn’t include the vertex shader. So I was just using it wrong. That’s my bad.
- 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.4 Release
I definitely want to learn how to make and use shaders with this because I saw what you did with the lighting in that Flamerunner game and would love to have some sort of lighting in my game so I can have dark moody areas and not just have everything so perfectly lit throughout. Seems I'll have to do modifications to the shaders you made for that since it was written before g3d was made so it's more self-contained.
I'm also curious about the collision code that's included. What's capsule collision? I've been using Bump for years as it's simple to use but it doesn't do angled surfaces. Does the collision here do that?
I'm also curious about the collision code that's included. What's capsule collision? I've been using Bump for years as it's simple to use but it doesn't do angled surfaces. Does the collision here do that?
- groverburger
- Prole
- Posts: 49
- Joined: Tue Oct 30, 2018 9:27 pm
Re: Groverburger's 3D Engine (g3d) v1.4 Release
No prob, happy to help.
Yep, the collision here works on any angled surfaces. The collision code tests basic geometric shapes like spheres, rays, capsules against the model's mesh, so anything in the model's mesh is fair game.Jasoco wrote: ↑Mon Oct 25, 2021 11:24 am I definitely want to learn how to make and use shaders with this because I saw what you did with the lighting in that Flamerunner game and would love to have some sort of lighting in my game so I can have dark moody areas and not just have everything so perfectly lit throughout. Seems I'll have to do modifications to the shaders you made for that since it was written before g3d was made so it's more self-contained.
I'm also curious about the collision code that's included. What's capsule collision? I've been using Bump for years as it's simple to use but it doesn't do angled surfaces. Does the collision here do that?
I'd recommend this article to learn about capsule collision, it's what I referenced when implementing it in g3d.
You can also take a look at this basic first person movement engine I whipped up back in January in this Github repo. It works pretty well but still has a little bit of jank to it (like going down slopes) that I've improved in my own personal projects since then. I'll get around to updating it soon.
Also to answer your question from a few days ago about whether models that are not in frame are still drawn and calculated -- yes, they are. However drawing models is super fast so unless you have a ton and start to feel your performance drop, it probably wouldn't be useful to try to implement any custom frustum culling. Something to note in g3d is that it's more efficient to have fewer complicated models than many simple models, so if you can combine them I would recommend doing so.
Re: Groverburger's 3D Engine (g3d) v1.4 Release
Can anyone explain why all tutorials on GLSL have this main() function but love2d works with effects?
Should I assume that the entire file will be included into main() ?
But main has no real return value, since it's void.
Seems like I'm googling it wrong, 'cause I can't find a simple example of ambient lighting + a point light source that I can plug in and get anything but pitch black screen.
Well, ok, the builtin one works just fine but I can't make things darker and illuminate a portion of a map with a light source.
I've looked at the suggested tutorial, but struggle to comprehend any of that, cause I can't plug it somewhere and toy with it till it'll make some sense.
Any help?
Should I assume that the entire file will be included into main() ?
But main has no real return value, since it's void.
Seems like I'm googling it wrong, 'cause I can't find a simple example of ambient lighting + a point light source that I can plug in and get anything but pitch black screen.
Well, ok, the builtin one works just fine but I can't make things darker and illuminate a portion of a map with a light source.
I've looked at the suggested tutorial, but struggle to comprehend any of that, cause I can't plug it somewhere and toy with it till it'll make some sense.
Any help?
Who is online
Users browsing this forum: No registered users and 2 guests