How to get modulate info in shader Canvas Item

Godot Version

4.3

Question

I need to get the albedo information of a color gradient from line2d how can I do it please help me. The only information I found was that in version 3.5 shader type canvas_item had a built-in variable vec4 MODULATE, which disappeared from the documentation for 4.x version.

After some time 2 ways of solution were found

1) Own modulate variable
Declare a variable in the shader that will represent your MODULATE and further do the necessary work with it.

Example:

shader_type canvas_item;

uniform vec4 my_modulate: source_color;

void vertex() {
	
}

void fragment() {
	vec4 texture_p = texture(TEXTURE, UV - vec2(TIME, 0.0));
	COLOR.rgb = texture_p.rgb;
	COLOR.a = my_modulate.a*texture_p.a;
}

2) Take COLOR information from vertex()
CanvasItem shader documentation says the following:

In the vertex() function, COLOR contains the color from the vertex primitive multiplied by the CanvasItem’s modulate multiplied by the CanvasItem’s self_modulate

This means that at the input to the vertex() function the COLOR value, very roughly speaking contains the total modulate value we need (total because of the modulate*self_modulate multiplication and other transformations). We only have to write it into a variable and do the necessary work with it. But you must remember that these are the vertex color values and not modulation, with all the advantages and disadvantages that come with it.

Example:

shader_type canvas_item;

varying vec4 vertex_color; 

void vertex() {
	vertex_color = COLOR;
}

void fragment() {
	//usage example
	vec4 texture_p = texture(TEXTURE, UV - vec2(TIME, 0.0));
	COLOR.rgb = texture_p.rgb;
	COLOR.a = vertex_color.a*texture_p.a;
}

For me, the 2nd method turned out to be the best since I needed to extract the gradient data from line2d
I hope I helped a wandering newbie like me in writing his first shaders.