godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Add a Texture Offset property to Line2D #450

Open HeartoLazor opened 4 years ago

HeartoLazor commented 4 years ago

Describe the project you are working on: A shmup with a cute dog. I'm rendering a closed path 2d with a line 2d node using a texture.

Describe the problem or limitation you are having in your project: I want to "scroll" the line 2d node texture by an offset, but I can't find a way in the inspector.

Describe how this feature / enhancement will help you overcome this problem or limitation: This feature will help me to make more easy closed seamless line 2d rendered textures at the ending points.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work: image Using this texture: gravity_control_rail At the mouse the line 2d "closes", but the texture yellow part is visually broken. That can be easily fixed with an offset texture var in the line 2d.

Describe implementation detail for your proposal (in code), if possible: A new var named "texture offset" at the fill section of line 2d. The var range is 0.0 to 1.0, where 0.0 is no offset and 1.0 is full width texture offset.

If this enhancement will not be used often, can it be worked around with a few lines of script?: No, because I can't find a way to override the line 2d renderer and override the whole drawing for this feature should be overkill.

Is there a reason why this should be core and not an add-on in the asset library?: It's a limitation with the line 2d nodes and an add-on to fix this don't make sense. There are more applications for this feature like scrolling animated beams, electricity, water or as my case making sure a closing line 2d is seamless.

CedNaru commented 4 years ago

Hi, In that case, why can't you use a simple shader that add an offset directly on the UVs ? You can control the offset with a material parameter instead of a node's property. It would even be possible to add a slight scaling effect in order for your yellow points to have a constant distance from each other. It would stretch the texture a bit, but it won't be noticeable if your line is long enough ( unless you want pixel perfect ).

HeartoLazor commented 4 years ago

Hi, In that case, why can't you use a simple shader that add an offset directly on the UVs ? You can control the offset with a material parameter instead of a node's property. It would even be possible to add a slight scaling effect in order for your yellow points to have a constant distance from each other. It would stretch the texture a bit, but it won't be noticeable if your line is long enough ( unless you want pixel perfect ).

I know that shaders resolves the problem in line 2d, but as a comparison I use the rect property of sprite for scrolling the uv in my plasma beams instead of a shader, because is less hassle. https://www.youtube.com/watch?v=K1eIEuqxoxw So, ¿Why doesn't line 2d have something similar?

Calinou commented 4 years ago

I started working on implementing this feature: https://github.com/Calinou/godot/tree/line2d-add-uv-offset-property

However, beveled lines will have broken UVs as the UV offset is increased. I'm not sure how to fix this. Any pointers?

image

CedNaru commented 4 years ago

image

In that part you added the offset again to a previous UV. (which should already have the offset) So in sharp angles, you probably cumulated the same offset many times. You did the same thing in another part of the code as well.

Calinou commented 2 years ago

In that part you added the offset again to a previous UV. (which should already have the offset) So in sharp angles, you probably cumulated the same offset many times. You did the same thing in another part of the code as well.

Thanks for the advice :slightly_smiling_face:

I pushed a rebased version, and the original code is no longer present at that location. Nonetheless, the issue with beveled corners is still present.