Zylann / godot_atmosphere_shader

Planet atmosphere shader for Godot Engine
Other
90 stars 7 forks source link

No clouds at all #3

Open Anyeos opened 9 months ago

Anyeos commented 9 months ago

I don't know how you achieve the clouds but on my case always I get some rendering of a cloud form on the other side (far in horizon) of the planet. It is like an concave mirror where you see too far and too distorted. That is how my clouds are rendered and barely I can see it. image

Zylann commented 9 months ago

Do you have a minimal test project that reproduces the issue, so it can be easier to investigate? This looks like the solar system demo, which is not a small project, so it's harder to figure out what causes the issue.

Zylann commented 9 months ago

There is a small demo scene with clouds in the atmosphere plugin. It works fine in Godot 4.1.3 (vanilla), and also Godot 4.2: image image

I'm on Windows 10 with nVidia 1060.

Also tried solar system (which requires my custom build of Godot because it uses the voxel module), works too image

Eerrikki commented 3 months ago

TL:DR clouds does not work in double precision release

Im having the same issue. While testing the solar system demo, i rescaled earth to planet.radius = 6371.0 instead of 1800.0 and enabled large_scale mode. I was amazed to see it actually worked, but when i landed and exited the ship, i could not move. So i downloaded your double precision release, and im amazed again... i can actually move around on the surface without problems but the clouds are not rendered correctly and i experience exactly the same as Anyeos described.

Zylann commented 3 months ago

Unfortunately there is nothing I can do without a proper repro (minimal test project?), especially if you're also using Godot 4.2. Because everytime I try this, clouds work for me (see screenshots I posted). I can't fix something if it doesnt happen. It's really frustrating :( If you're using Godot 4.3, there is a patch for reverse-Z that should be done to make the shader work, but that's not just about the clouds so I dont know.

Eerrikki commented 3 months ago

to replicate: run the solar system demo in godot.windows.editor.x86_64.exe and clouds work run the solar system demo in godot.windows.editor.double.x86_64.exe nd clouds do not work

image1 image2

Zylann commented 3 months ago

If that's really the only difference then I'm very puzzled as to what is actually going on... Godot is doing something different in double precision somehow, but I don't know what it would be that affects that specific part of the shader and yet the atmosphere still renders...

Zylann commented 3 months ago

I suspect this is a Godot issue: https://github.com/godotengine/godot/issues/85711 There is an argument against using INV_VIEW_MATRIX in large worlds, however as you experienced, precision loss doesn't affect clouds, which are never rendered close enough to have noticeable artifacts (they are fuzzy so "close" makes little sense). Still, the matrix might be wrong...

Zylann commented 3 months ago

Notably, for some reason, INV_VIEW_MATRIX has its origin negated in double-precision builds. I don't know why, likely a bug. You could try to modify the shader you're using by doing this change:

void fragment() {
    bool b_discard = false;
    mat4 inv_view_matrix = INV_VIEW_MATRIX;
    inv_view_matrix[3][0] *= -1.0; // <-- undo origin negation
    inv_view_matrix[3][1] *= -1.0;
    inv_view_matrix[3][2] *= -1.0;
    atmosphere_fragment(u_depth_texture, SCREEN_UV, INV_PROJECTION_MATRIX, inv_view_matrix, // <-- pass it here
        VIEWPORT_SIZE, v_planet_center_viewspace, v_sun_center_viewspace, ALBEDO, ALPHA, b_discard);
    if (b_discard) {
        discard;
    }
}
Eerrikki commented 3 months ago

I can confirm that the snippet you provided indeed fixes the clouds :D

Thank you Zylann for such dedication to innovate and develop these tools and consepts. It is very inspirational and shows a huge potential!