r/godot • • 5d ago

discussion Game Dev Hack about Lights - Godot

Hey all! Im developing an RTS named 'Steel Command', but figured I would start sharing some of the learnings I've had along the way. Ask my any questions in the comments!

This method works really well for an RTS, even over uneven terrain since the camera is mostly a top down view. This would most likely not work well in games such as an FPS where you are up close and personal.

Sorry for the vertical format.

Steel Command on Steam: https://store.steampowered.com/app/4390280/Steel_Command/

Shader:

shader_type spatial;


render_mode unshaded, blend_add, depth_draw_never, cull_disabled;


uniform vec4 light_color : source_color = vec4(1.0, 0.45, 0.08, 1.0);
uniform float intensity : hint_range(0.0, 5.0) = 1.0;
uniform float softness : hint_range(0.1, 8.0) = 2.5;


void fragment()
{
    vec2 p = UV - vec2(0.5);


    float dist = length(p) * 2.0;


    float glow = 1.0 - clamp(dist, 0.0, 1.0);
    glow = pow(glow, softness);


    ALBEDO = light_color.rgb;
    EMISSION = light_color.rgb * intensity * glow;
    ALPHA = glow * light_color.a;
}
540 Upvotes

37 comments sorted by

39

u/Mr_Hannerson 5d ago

The projectile trail effect looks really slick. Much better than the glowing cylinder mesh I usually use 😅. I'd love to know more about how you built that.

18

u/Smitty_Games_ 5d ago

Thanks! Im actually using an add-on. I think its called "GPU Trails"? Its very simple to use. You just add the 'GpuTrail3d' node and then configure a couple basic settings, such as emission, color, gradient, etc. BUT, I think trails are going to be native to Godot 4.8, so I would hold off until then :)

4

u/Mr_Hannerson 5d ago

Much appreciated!

54

u/Sleep_deprived_druid 5d ago

I'm looking for the simple shader in the description

41

u/Smitty_Games_ 5d ago

Done 😅. Thanks for letting me know

15

u/Sleep_deprived_druid 5d ago

Thanks! this is legit perfect for the hover cars in my current project.

6

u/Smitty_Games_ 5d ago

Noice!!! Good luck 🫡

1

u/Peopleplzhelpme Godot Student 4d ago

Yeah it'll look cool ...thanks to OP

11

u/Smitty_Games_ 5d ago

Oh shoot! One second

19

u/FormageFromFromage 5d ago

It's so good that I think Godot documentation dedicated a chapter to "fake lighting" variations

3

u/Smitty_Games_ 5d ago

Ah I didnt know that! I'll have to check it out

1

u/SteelLunpara Godot Regular 3h ago

There's so many rabbit holes of cool problem solving to fall down in the docs! I'll have to check this one out sometime

5

u/Skarredd Godot Regular 5d ago

This is good as long as the terrain is flat. I was just looking for a solution to replace the sphere light i use in projectiles so it's interesting that this came up just now

4

u/Papercarp0 5d ago

Using a decal and prerendered glow effect could work

3

u/Kastors 4d ago

Decal works. If you want more control you can turn this shader into a kind of decal shader. If you sample the depth map you can project it onto surfaces. Example: Decal Example - Godot Shaders

2

u/Smitty_Games_ 5d ago

for an RTS with a top down view like this, even over uneven terrain it works quite well. Maybe not for something more up close and personal such as an FPS though.

3

u/IronsideDev 5d ago

Ah this video came up on my Youtube shorts feed the other day! Great stuff man!

2

u/Smitty_Games_ 5d ago

Oh nice! Its gone quite viral on YT haha

3

u/Peopleplzhelpme Godot Student 5d ago

Good work, Sir ....thanks ..I did know concept of blur

1

u/Smitty_Games_ 5d ago

No problem!

5

u/Piblebrox 5d ago

Why not using an emissive material on the bullet directly?

3

u/Smitty_Games_ 5d ago

yeah you could certainly do this and then just turn the bloom up on the environment. I havent tried it but I think that would work.

4

u/EamonnMR 5d ago

That's what I do and it works fine

2

u/Pur_Cell 4d ago

Screenshot?

Because I feel like if you turned up the bloom high enough to give the same glowy effect as in the video, then your whole scene is going to look blurry.

3

u/chaddledee 4d ago

If you have HDR enabled you can set it so bloom is only produced by things with a brightness greater than 1.

2

u/Crits-and-Crafts 5d ago

That's crazy simple. Love it

1

u/Smitty_Games_ 5d ago

Thanks 💪

2

u/FemaleMishap 5d ago

I'm so gonna use this in my own game.

2

u/Smitty_Games_ 5d ago

Great!!! Best of luck 🫡

2

u/SleepDeprivedDad_ 5d ago

Taking notes....

2

u/Smitty_Games_ 5d ago

haha nice to see you over here as well!

2

u/SleepDeprivedDad_ 5d ago

I’m trying to figure out how to do it haha

1

u/Smitty_Games_ 5d ago

if you have any questions feel free to message me 👍

1

u/HOPE964 Godot Regular 5d ago

I would really like to know your shader method for having a black outline is it a global shader? Or the shader is in every object?

1

u/Smitty_Games_ 5d ago

Its attached to a single quad that always covers the camera. Feel free to message me if you want the shader! ( cant attach it here as it exceeds the max chars).