RetroFed Forums
Your home away from modern life.
Godot 4: Custom lighting in 3D (tutorial)
Post Reply
AuthorMessage
FencerDevLog
programming.dev
FencerDevLog@programming.dev
Joined: 2023-10-18
Posted:   Subject: Godot 4: Custom lighting in 3D (tutorial) Quote

Hello, everyone! Let’s again create a spatial shader for a 3D object. This tutorial is special because for the first time I will touch on a function that I have completely ignored so far. It is the function called light, and I will show how we can work with it.

24   Original
insomniac_lemon
lemmy.cafe

insomniac_lemon@lemmy.cafe
Joined: 2024-11-20
#2 Posted: · edited   Subject: Re: Godot 4: Custom lighting in 3D (tutorial) Quote Reply

Youtube encoding doesn't help, but I'm not sure about the "fire" effect here.

It reminds me of when I turned Minecraft's end skybox into a purple-ish Moiré pattern (no shader needed, just a checkerboard texture viewed at a distance+angle).



Back to Godot, I made a toon-like light shader with the step function being the important bit*. It is probably good enough to use, though it's a bit frustrating how I can't seem to keep input colors accurate. Ambient color works acceptably, though I somewhat wish I could control it more, also seeing issues with light range/multiple lights.

I also haven't found a good way to handle light color. I can ignore it or mix color (can look ugly). It's probably possible with dot() but I can't seem to do it right.

Using HSV is probably needed here, although to me it seems like an absolute mess without it being built-in.

* unshaded+1 shadow w/ambient with DIFFUSE_LIGHT = , 5(?) shades with DIFFUSE_LIGHT += but it's also too bright

EDIT: I've figured it out by going by the docs again, I did need ATTENUATION and += to properly handle shadows and multiple lights respectively. I also have LIGHT_COLOR with dot() in a way I like (currently handling it in each rgb channel), though it can still render incorrectly if looking through a spotlight of a different hue (attenuation makes it worse).

1
jaydom28
lemmy.today
jaydom28@lemmy.today
Joined: 2026-07-02
#3 Posted:   Subject: Re: Godot 4: Custom lighting in 3D (tutorial) Quote Reply

I started learning Godot about 2 weeks ago. I feel an urge to save all these vids for when I need them haha

1
FencerDevLog
programming.dev
FencerDevLog@programming.dev
Joined: 2023-10-18
#4 Posted:   Subject: Re: Godot 4: Custom lighting in 3D (tutorial) Quote Reply

Youtube encoding doesn't help, but I'm not sure about the "fire" effect here. It reminds me of when I turned Minecraft's end skybox into a purple-ish Moiré pattern (no shader needed, just a checkerboard texture viewed at a distance+angle). Back to Godot, I made a toon-like light shader with the step function being the important bit*. It is probably good enough to use, though it's a bit frustrat...

Yeah, I don't say it's the best possible simulation. It could be a lot better. The point was to demonstrate the usage of the light() function, mostly.

1
FencerDevLog
programming.dev
FencerDevLog@programming.dev
Joined: 2023-10-18
#5 Posted:   Subject: Re: Godot 4: Custom lighting in 3D (tutorial) Quote Reply

I started learning Godot about 2 weeks ago. I feel an urge to save all these vids for when I need them haha

Good luck. 😎

2
Post Reply
Back to top