I have a canvas_item shader with a uniform variable that alters the shader at runtime using an AnimationPlayer. When I apply my shader to a TextureRect with a non-null Texture it works fine.

I now want to apply the shader to a Node2D with a custom draw. I only draw once on the initial call to _draw. The animated shader does not affect this node.

Are custom drawn CanvasItems immune to shaders? They seem to be but I can't find any documentation that says so.

This should be possible, you just have to pick the correct node during run-time and assign the correct shader/material iirc.

Yep, that's what I'm doing. I should be able to access the custom drawn data with the TEXTURE object inside the shader then?

This may be a bug. I'll create a small repro project to share; maybe I'm missing something obvious.

I made a demo project: https://1drv.ms/u/s!Aj0ttYc6OwxpkJAcWkboO0WpFEIJHg

It contains a Sprite using a png and a Node2 with a custom draw. Both nodes use a shader that animates the texture, gradually revealing and hiding the texture from left to right using a cutoff value. An AnimationPlayer animates the cutoff to perform the actual animation.

The Sprite node works fine, but the custom drawn Node2 doesn't display at all. If you remove the Material (with the shader) from the Node2 it draws fine.

Am I doing something wrong, or is this a bug with Godot?

I downloaded the project and I think I found what might be causing the shader not to work.

The problem seems to be on the following line:

float maskValue = texture(mask, UV).r;

As far as I can tell, the reason this is causing an issue with custom drawn Godot node is because the the UV property either isn't properly set, or all four of the UV points for the quad drawing the circle are set to the same point. (This seems more likely).

The only reason I think this is the case is because when you change the code to the snippet below, the rest of the code works as expected, albeit not like the shader is intended:

float maskValue = texture(mask, SCREEN_UV).r;

This is almost certainly a bug with the draw_circle function. If you replace draw_circle with draw_rect, it works as expected, though interestingly it goes opposite the direction of the sprite node.

The reason for it going in the opposite direction is because of the way I keyed the animation, so that's OK.

I experimented some more. It seems draw_circle and draw_polygon both fail to work, whereas draw_rect does.

I'll log a bug. Thanks for the assistance!

@Zodman said: The reason for it going in the opposite direction is because of the way I keyed the animation, so that's OK.

I experimented some more. It seems draw_circle and draw_polygon both fail to work, whereas draw_rect does.

I'll log a bug. Thanks for the assistance!

Great! I'm glad I was able to be of some assistance. Hopefully it can be fixed in the future.

(Side note: sometime soon I'll look at editing the QnA plugin so it doesn't move the answer, as in my opinion it breaks the conversation flow)

(Side note: sometime soon I'll look at editing the QnA plugin so it doesn't move the answer, as in my opinion it breaks the conversation flow)

I agree. Copying the answer to the top may serve a wider variety of conversations.

Also, I couldn't delete my own post (hence the clumsy (deleted) post, which followed a "failed" attempt to Post Comment with an incompatible file attached (the zip).

Thanks again, I really appreciate your efforts.

4 years later