Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fireflies on terrain #416

Closed
TokisanGames opened this issue Jul 9, 2024 · 2 comments
Closed

Fireflies on terrain #416

TokisanGames opened this issue Jul 9, 2024 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@TokisanGames
Copy link
Owner

TokisanGames commented Jul 9, 2024

Description

With a light background and dim light, it's possible to see white dots or fireflies from the background through the terrain, even though the meshes are perfectly aligned. It changes based on camera position, angle, and viewport aspect ratio.

This issue was discovered and worked around in Godot 3. I hadn't been able to reproduce it in GD4 until today. It is easily reproducable in the demo by turning off the light and brightening up the ground color in Sky and moving the camera around.

image

I was most strongly seeing it along the highlighted areas.

image

Fortunately, the same fix works.
godotengine/godot#35067 (comment)

It's an issue in the godot renderer. The most effective solution is to avoid using the default model space to view space transform in one operation (MODELVIEW_MATRIX) by adding the skip_vertex_transform render mode. Then we do our own conversion in two separate steps at the end of vertex().

	VERTEX = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
	VERTEX = (VIEW_MATRIX * vec4(VERTEX, 1.0)).xyz;

cc: @Xtarsia

@TokisanGames TokisanGames added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Jul 9, 2024
@TokisanGames TokisanGames changed the title Fireflies in terrain Fireflies on terrain Jul 9, 2024
@TokisanGames
Copy link
Owner Author

TokisanGames commented Jul 9, 2024

Fixed in 1a312cc and 336f462

@TokisanGames TokisanGames added this to the Beta 0.9.x milestone Jul 9, 2024
@TokisanGames TokisanGames self-assigned this Jul 9, 2024
@TokisanGames
Copy link
Owner Author

TokisanGames commented Jul 9, 2024

I discovered this fix introduces striations to the Normal shadows. It also subtly responds to camera angle. This page says more is needed:
https://docs.godotengine.org/en/4.2/tutorials/shaders/shader_reference/spatial_shader.html#vertex-built-ins

NORMAL = normalize((MODELVIEW_MATRIX * vec4(NORMAL, 0.0)).xyz);
BINORMAL = normalize((MODELVIEW_MATRIX * vec4(BINORMAL, 0.0)).xyz); //optional
TANGENT = normalize((MODELVIEW_MATRIX * vec4(TANGENT, 0.0)).xyz); //optional

Only the Normal line is needed, but I added all. This gives the identical visual appearance as before, however it is 0.10ms faster, or 10-40fps! I added those and improved the lighting by blending the splits, which took a little performance.

Fixed in f5f676f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

1 participant