Shader displaying in the editor, but not during runtime

Godot Version

4.3

Question

Hello, I’ve been trying to replicate a simple fog effect from this video. It works fine in the editor and as it’s own scene, but it doesn’t display when my entire game is running. The Nodes ParallaxBAckground/Layer/ColorRect do appear in the Remote tree, but they are just invisible.

I’m stuck on this for days and I exhausted every possibility I could think of before posting this topic (I read the other similar topics too without finding what is causing this.)

shader_type canvas_item;
uniform vec4 base_color: source_color;
uniform sampler2D noise_texture: repeat_enable, filter_nearest;
uniform float density: hint_range(0.0, 1.0) = 0.25;
uniform vec2 speed = vec2(0.02, 0.01);

void fragment() {
	vec2 uv = UV + speed * TIME;
	float noise = texture(noise_texture, uv).r;
	float fog = clamp(noise * 2.0 - 1.0, 0.0, 1.0);
	COLOR.a *= fog * density;
}
1 Like

Are you setting all the uniforms properly in the game?

What are you seeing when it doesn’t work? Nothing? A white texture?

What do you mean by “settings all the uniforms in the game”? I do not modify them outside of this script. I tried tweaking them in the Inspector but nothing changed.

When it doesn’t work, nothing displays at all.

You have no default values for base_color and noise_texture in your shader, so unless you set them either in the editor or a script…

You’re setting COLOR.a, but what about COLOR.rgb?

The values in the editor are the default one (white, no transparency.)

The weird thing is that the Shader is displayed when I run the scene (F6), but not the full game (F5). Yet the values are the same for both.

First determine if the problem is shader itself or your node setup. Assign a dummy shader that outputs flat color and see if its drawn when you run the project.

1 Like

Check if something may be removing the (I’m guessing this is a ColorRect) during the runtime (via free() or queue_free())

You aren’t assigning COLOR.rgb. I’m not sure what default values they get, which could be any preset color or “whatever was in that memory”. It might differ depending on where it runs.

I’d suggest setting it to vec3(1.0, 0.0, 1.0) and see if you get magenta fog.

This was the answer, thank you so much!
I recreated the Scene node by node, starting with a dummy texture like you suggested. Then I made sure it stays visible in game with each step, until it was complete and finally visible.
I still don’t understand why the original is invisible since its parameters are identical to the copy, though.

1 Like

Something probably got screwed up in your scene setup.

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