Visual Shader Time Not Passing Properly

Godot Version

v4.4.1

Question

Hi all,

I’m trying to transfer over a VShader that I’ve developer for a Spatial environment into a CanvasItem environment.

It’s a fairly simple shader, but I’ve cut it down through my debugging process to an extremely simple shader of Time → Vec2 Multiplier → Texture2D → Color for the sake of demonstrating this and still I’m having no luck.

Am I missing something silly that’s different in how we handle time in CanvasItem versus Spatial shaders?

It should just fade from black to white and then jump back to black as it does in Spatial right?
Instead it just stays and white.

I can force the transition with a Float Constant from 0 to 1.

Any help on this would be greatly appreciated.

Many thanks,
Ben

Edit: I’ve translated this to a standard Shader and am having the same problem.

shader_type canvas_item;
render_mode blend_mix, unshaded;

uniform sampler2D GradientTexture;

void fragment() {
// VectorOp:3
	vec2 _UV = TIME * vec2(0.2, 0);
// Texture2D:2
	vec4 Output = texture(GradientTexture, _UV);
// Output:0
	COLOR.rgb = vec3(Output.xyz);
}

In 2D (canvas items) the texture repeat setting is set to Disabled by default that’s why it stays white. In 3D (spatial) the texture repeat settings is set to Repeat by default and that’s why it jumps from white to black.

You can set the CanvasItem.texture_repeat to Repeat and it should work. Or you can do it globally by setting Project Settings / Rendering / Textures / Canvas Textures -> Default Texture Repeat to Repeat

That’s a great pointer, I had no idea that setting existed.

It’s still not resolved the issue though unfortunately.
I’ll run through the settings here.

Default Repeat is enabled.

I’ve also set the gradient texture to repeat as a further attempt (it previously was set to no repeat).

And the following are my settings for the VShader itself.

I’ve also tried setting repeat on the CanvasItem itself.

The image still remains simply white.

Oh, I see. It’s not possible to specify the repeat mode when using a Texture2D node directly in the visual shader. You’ll need to use a Texture2DParameter node, change the Texture2D mode to SamplerPort and connect the Texture2DParameter sampler2D port to the Texture2D sampler2D port. You’ll need to specify the repeat mode in the Texture2DParameter node. You’ll also need to setup the texture in the inspector under Shader parameters inside the Shader

Alternatively, you can just use the qualifier repeat_enable in the text version.

shader_type canvas_item;

uniform sampler2D my_texture: source_color, repeat_enable;

void fragment() {
	vec2 uv = TIME * vec2(0.2, 0.0);
	COLOR = texture(my_texture, uv).rgba;
}

This is absolutely the solution, thanks for the help.

I feel that Texture2D should have this repeat option as well, save adding extra nodes but it is just one additional node so not too much bloat really.

Massively appreciated, thanks @mrcdk!

(Here’s what I ended up with that resolved the issue, highlighting the property that has to be set)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.