godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.57k stars 21.09k forks source link

Vulkan: GPUParticles trails show jagged shapes #57750

Open QbieShay opened 2 years ago

QbieShay commented 2 years ago

Godot version

v4.0.alpha.custom_build [a6abeb6b2]

System information

Linux Arch, Radeon RX 590, Vulkan renderer

Issue description

Particle trails show jagged shapes, see video for more clarity. On top, a quad mesh On the bottom, a particle trail

They share the same shader

(Texture is made by me and CC-BY)

https://user-images.githubusercontent.com/7917475/152778286-9060e18b-1b92-4f0b-9f5c-748f7cbd2570.mp4

Steps to reproduce

Open MRP

Minimal reproduction project

trailrepro.zip

nevarek commented 2 years ago

Increasing the number of section segments on the ribbon trail reduces the blockiness, is this a sufficient fix?

Calinou commented 2 years ago

Increasing the number of section segments on the ribbon trail reduces the blockiness, is this a sufficient fix?

The preview looks more blocky than it could be with a given number of segments in the trail. Therefore, I think increasing the number of segments only hides the original problem rather than resolving it.

Calinou commented 1 year ago

With modified texture and subdivisions lowered to 1 for easier comparison (texture isn't seamless, ignore the seam in the middle):

Shaded

2022-11-07_20 40 14

Wireframe

2022-11-07_20 41 52

I remember this kind of jagged UV effect quite often in games, so I'm not sure if it can be resolved without increasing the number of subdivisions.

trailrepro2.zip

Calinou commented 1 year ago

This can apparently be fixed with a custom spatial shader applied to the mesh's material: https://godotshaders.com/shader/trail-dewiggle/

Shader code for posterity (credit: celyk) ```glsl shader_type spatial; render_mode unshaded,blend_add,cull_disabled,particle_trails; uniform sampler2D texture_albedo : source_color; varying float scale_interp; void vertex() { // dewiggle scale_interp = length(VERTEX.xz); UV *= scale_interp; } void fragment() { vec2 base_uv = UV; // dewiggle base_uv /= scale_interp; vec4 albedo_tex = texture(texture_albedo,base_uv); ALBEDO = COLOR.rgb * albedo_tex.rgb; ALPHA *= COLOR.a * albedo_tex.a; } ```
QbieShay commented 1 year ago

This is also easy to mitigate by adding an extra edge in the middle of the trail. I'll open a proposal