this post was submitted on 30 Aug 2024
1 points (100.0% liked)

Godot

5840 readers
3 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

[email protected]

Credits

founded 1 year ago
MODERATORS
 

I'm thinking about making a character entirely out of Polygon2D nodes without textures. One thing I haven't figured out how to do is make each polygon cast a "permanent" shadow on top of the ones that are Z levels below it.

Below is an image of what I want to do, but using shaders/lights. I've only managed to do this by making extra polygons to fill in as the shadows.

How exactly do I have to set up a light source to achieve this effect? Using a DirectionalLight2D or a PointLight2D just brightens the polygons and I can't figure how to use a LightOccluder2D, or even if this is the correct way to get this result

(The polygons are green due to the DirectionalLight being green) - The occlusion simply applies the shadow on anything that is Z levels below it.

top 3 comments
sorted by: hot top controversial new old
[–] [email protected] 0 points 2 months ago (2 children)

Are you set on using light sources, or would you be okay with a shader that just creates the shadows without checking for specific light sources? It looks like this might do what you want, but you might need to modify it to work with your exact use case (multiple z levels).

Generally it seems like some kind of shader might be your best option, it seems like the 2d lights are intended for casting lights within a given z level rather than between them. If you want more complex shadows across multiple z levels, you might need to create your own light objects (just a position, color, and intensity) and pass them to a shader that does something similar to the linked example, but modified based on your lights list.

It's possible there's a simpler way that someone else could chime in with (I'm pretty new to godot), but as far as I can tell the built in 2d light and shadow systems aren't designed for different z levels, so you'd need to use something else.

[–] [email protected] 0 points 2 months ago

FWIW I was trying to do something like this and ended up with pretty much what you describe - some custom shading to get everything working.

[–] [email protected] 0 points 2 months ago

That's exactly the kind of thing that I need, just a shame I need to have a texture on the polygon and, code as is, it offsets the texture a lot compared to the polygon's center. While not "ideal", I can probably work with this, though creating anything other than squares will be quite a pain if I don't use large textures, due to the zoom level of Godot's UV editor

I'll mess around and see if I can get it to work as I want until a more definitive solution shows up, thanks!