0
\$\begingroup\$

Goal: car sprites with one showing headlights

How can I best simulate headlight beams, in a night-time scenario, in Godot 4?

The components I have are all sprite-based - a top-level car sprite, a shadow sprite (that is offset based on time-of-day, and changes), and a lane sprite (the D) that is attached to the car. This is on top of a road-bitmap, that will itself have its darkness/brightness adjusted based on time-of-day. The components:

godot game nodes

I can think of three ways that might work:

  • Add a new sprite, (toggleable, with adjusted opacity) and offset it in front of the car sprite.
  • Use actual tiny 2D point-source lights (all I know about Godot's lighting, is that it exists).
  • Add a shader - somewhere... I'm definitely not conversant in shaders - maybe it would go on the road bitmap, with a bunch of tiny coordinates?

I'm fairly sure option 1 would work - adding a new sprite to the node-stack, offset ahead of the car sprite. I'd have to play around with Z-levels, etc, but think it would work.

Option 2 presumably would work, but would you have issues with performance (likely several dozen sprites on the screen at once).

Option 3 - not sure I like the idea of shaders, but it so often seems to be the answer - "just use a shader!" :)

For the record, originally the shadow-sprite was going to be a shader, but a blurry dropdown-shadow shader that I found turned out to have hideous performance. I'm told that's a general problem with blurry shaders, as they have nested for-loops that drive performance down. So would a bunch of blurry headlight shaders do the same thing?

I'm not looking for a photo-realistic effect, just something that shows the concept that it's got headlights on at night. I am looking to keep FPS up, of course.

\$\endgroup\$
2
  • \$\begingroup\$ The preview in your goal image looks the most like what you'd get from Option 1. Have you tried that route, and are there any drawbacks or aspects you're unsatisfied with in that approach? The main one I can think of is that the sprite wouldn't "illuminate" a car ahead where they overlap - it would just get drawn above or below - but maybe that's OK or desirable for your visual style? You can avoid a negative performance impact from a realtime blur shader by pre-computing the blur in a texture you use as input to the shader, though even mobile GPUs should be up to plenty of blurring. \$\endgroup\$ Commented Aug 30 at 14:21
  • \$\begingroup\$ @DMGregory yeah, the preview is just hand-drawn pixels, with Gimp, I haven't tried any approach yet. And pre-computing would be essentially doing option 1, where the sprite was previously-constructed, whether by shader or Gimp. (That's how I finally did the shadow-sprite, in Gimp, after the shader was a bust). Oh yeah, as to the "illumination" - it would be nice to do, if it's feasible. That's sort of the problem, I'm not enough of a Godot guru to really do a cost/benefit analysis of all the options. \$\endgroup\$ Commented Aug 30 at 14:26

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.