Not sure if this is expected or I have done something wrong but when I try to get the y pixel size of a Line2D it seems to be fixed at 1 / 64 no matter what I set the actual width of the line to be. Below is some shader code to demonstrate, just attach this to a line 2D then change the line width. Switching out the last 2 lines in the shader should show a difference if the Y pixel size is anything other than 64, but it's always the same:

shader_type canvas_item;

void fragment(){ 
	vec2 size_Local = 1.0 / TEXTURE_PIXEL_SIZE; // this is the pixel size of the texture in texture pixels
	//COLOR = vec4(0.,UV.y * size_Local.y / 64.,0.,1.);
	COLOR = vec4(0.,UV.y ,0.,1.);
}

I continued to test this and it suddenly changed to not be 1 / 64 but be 1 / 1. I think TEXTURE_PIXEL_SIZE just does not work how I expected (I had a texture that was 64 pixels high attached to the line2d, so that was where it came from).

Instead of using TEXTURE_PIXEL_SIZE I will pass in the line2d width to a uniform which should then do what I want, obvious now I think of it.

Shaders work on a low-level of the pipeline, that deals with vertices and pixels (fragments). It doesn't have access to the high-level constructs (like a Line2D or Sprite or whatever). If you need additional information, you would create a shader parameter (a uniform) and pass that in from the editor.

a year later