Zylann / godot_heightmap_plugin

HeightMap terrain for Godot implemented in GDScript
Other
1.77k stars 160 forks source link

Terrain random flashs #469

Open wizardCyb opened 1 day ago

wizardCyb commented 1 day ago

When moving the camera around the terrain, I occasionally see random flashes. They occur on average about every five minutes during gameplay. The flashes of light usually appear around a black dot.

5

Environment

Zylann commented 1 day ago

Sorry but I don't know how to investigate that. I would need a minimal test project that shows this happening (and therefore allowing to change things confirming whether or not it fixes it). I haven't experienced this lately. Is that black dot present all the time or is it flickering or moving? Does this happen with a specific shader? With specific things present? How big and how bright are the flashes?

The only supposition I have is that maybe, in your particular setup, something causes a value in shader to become NaN or very high, outputting that black pixel and then cause a "flash" if you have a post-processing effect such as bloom or glow enabled because that tends to spread the bogus pixel around (but why every 5 minutes, mystery; and that's assuming Godot features you're using are bug-free). But without any way of reproducing this I can't investigate.

wizardCyb commented 22 hours ago

The black dot and glow around appears in a frame then the next one if the camera moves it is not there anymore. The glow is particularly noticeable because it flashes strongly, with an approximate radius of 50 pixels.

I'm using the Classic4 shader, but the issue persists when switching to Classic4Lite. I have the glow effect enabled, and it seems related to the issue. Disabling the glow prevents the problem, while adjusting the glow parameters increases or decreases the intensity of the effect.

Side note, turning on fog makes the issue disappear, though I'm not sure if this applies to all situations or fog distances.

The 5 minutes I mentioned was just to illustrate how rare the event is. It doesn’t mean it happens every 5 minutes. I might notice it 3 times in 10 minutes or not at all.

At the moment, I don’t have a minimal test project to share, and I haven’t tested the issue on a different computer. I can probably test it later.

Not sure if is related, but sometimes I got white or black dots, even sometimes are small lines. Like this:

8

Thank you.

Zylann commented 20 hours ago

Hmm I haven't seen lines like this either. I opened a few test scenes I had around and could not find anything. So I'm not going to be able to do further investigation without a way to confirm this, or you have to try changing things in the shader in your project.

If you have detail layers, try turning them off just in case.

An example of tests you could do, at the end of the terrain's fragment shader:

    // Attempts at sanitizing outputs to prevent NaNs/Infs/Illegal values
    ALBEDO = clamp(ALBEDO, vec3(0.0), vec3(1.0));
    ROUGHNESS = clamp(ROUGHNESS, 0.0, 1.0);
    NORMAL = clamp(NORMAL, vec3(-1.0), vec3(1.0));
    if (length(NORMAL) < 0.2) {
        NORMAL = vec3(0.0, 1.0, 0.0);
    } else {
        NORMAL = normalize(NORMAL);
    }

You could also try adding this one at the end of the vertex shader:

    NORMAL = clamp(NORMAL, vec3(-1.0), vec3(1.0));
    if (length(NORMAL) < 0.2) {
        NORMAL = vec3(0.0, 1.0, 0.0);
    } else {
        NORMAL = normalize(NORMAL);
    }

If that fixes it, remove them until you can identify which one causes it. If it doesn't, then it would be something else, but I don't know what (considering these are the only variables the shader passes over to Godot).