godot-extended-libraries / godot-next

Godot Node Extensions - Basic Node Extensions for Godot Engine
MIT License
957 stars 61 forks source link

Add support for trail gradienting in 3D #67

Closed I7SOD closed 3 years ago

I7SOD commented 4 years ago

Hi Guys I love your godot-next project I just wanted to propose that a gradient coloring scheme should be added to the trail 3D so as to allow something like this:

trail

But in a 3d space but I really don't know if that's possible so am hoping for a feedback

willnationsdev commented 4 years ago

Looks like the Trail3D script extends the ImmediateGeometry class. When I look at the API documentation for it, it seems that ImmediateGeometry extends the GeometryInstance class which has a material_override property on it. I'm pretty sure that if you assign a new SpatialMaterial to that property, and you set the albedo_texture property on that material to a new instance of GradientTexture, then you might be able to get the look you are seeking.

If I can find time to test out the idea myself, I will, but I'm pretty busy these days. I'd encourage you to give it a shot / experiment in the meantime.

I7SOD commented 4 years ago

Okay I will thanks for the feebback @willnationsdev

I7SOD commented 4 years ago

I used the gradient texture but it seems to use the first color only it discards every other color @willnationsdev

willnationsdev commented 4 years ago

Well, props to anyone who can figure out why that is. If I get time, maybe I can look into it, but I'm not really sure where to begin with that...

Firepal commented 3 years ago

This requires having a UV map on the generated mesh, which is two gradients that are used for texture mapping. (My profile picture is the debug view of a UV-mapped square! =)

Trail3D does not create a UV map for its generated mesh trail though, and the default UV map is just Vector2.ZERO, so only the GradientTexture's top-left corner pixel is sampled. Which is one color.

Generating UVs for ImmediateGeometry involves setting the UV value of each vertex in the code, it's not particularly difficult. I might try doing it!

Firepal commented 3 years ago

Doing interpolated UV mapping is really not clean with PRIMITIVE_TRIANGLES (because triangles aren't truly connected to eachother), I have a feeling that Trail3D could use PRIMITIVE_TRIANGLE_STRIP (switching to it is easier said than done haha)

Anyway, I got it working. Just gotta make the C# version and we're golden!

image