Issue with fragment shader on a ViewportContainer

Godot Version

3.5.3.stable

Question

I’m attempting to put this shader inside a a ViewportContainer’s material, and I can’t get the fragment function to run properly. Simply not having it causes the rest of the shader (vertex function) to work fine, adding the shader snippet causes it to show only the shift_color for output, and putting it inside an if statement causes the ViewportContainer to be simply not rendered when the condition isn’t met. Any ideas on how to fix?

shader_type canvas_item;

// --- Uniforms --- //
uniform bool use_grayscale = true;
uniform vec4 shift_color;

uniform float normal_offset : hint_range(0, 2, .1) = 1.5;
uniform float time_influence : hint_range(0, 50) = 3;
uniform float y_div : hint_range(0, 10, .1) = 2.87;
uniform bool off;

void vertex() {
	if (!off){
		VERTEX.x += sin(VERTEX.y * y_div + (TIME * time_influence)) * normal_offset;
		VERTEX.y += sin(VERTEX.x * y_div + (TIME * time_influence)) * normal_offset;
	}
}

void fragment() {
	if (!off){
		COLOR.rgb = mix(COLOR.rgb, vec3(0.299 * COLOR.r + 0.587 * COLOR.g + 0.114 * COLOR.b), float(use_grayscale));
		COLOR *= shift_color;
	}
}

merged with wobly 2d - Sokpop Based

nodehierarchy

What I’m attempting to achieve an underwater look for the 3D scene while on the pause menu. Here the (way too subtle) wobble effect is in show, with the fragment function commented out in its entirety.

Here the issue shows up. When the fragment function is skipped(off = true), the screen goes blank. When it runs, (off = false), shift_color shows up.

So I just figured out COLOR is not prefilled in ViewportContainer materials. Fix for the shader:

void fragment() {
	COLOR = texture(TEXTURE, UV);
	if (!off){
		COLOR.rgb = mix(COLOR.rgb, vec3(0.299 * COLOR.r + 0.587 * COLOR.g + 0.114 * COLOR.b), float(use_grayscale));
		COLOR *= shift_color;
	}
}

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