Godot Version
4.6 (Windows)
Question
I’ve been struggling to make this cool wireframe effect with a spatial shader that gives a gradient from the edges of each sharp edge-separated n-gon to the center (see demo picture).
This could be possible using poke faces and vertex colors in Blender, but the effect will probably be used across my entire game and I would rather avoid making that many destructive mesh edits. Instead, I’m wondering if it’s possible to do this on plain meshes without using any extra data, or if Godot could create that extra data during runtime, or ideally during import.
Ideally I also want the gradient to scale with vertex world coordinates and be consistent across differently sized meshes, so the generated normal for the gradient would only inform the direction, where the gradient itself would have a world-space length. In other words the gradient normal for each fragment should be from the closest edge, perpendicular and inward along the face - and that’s the problem since shaders can’t access advanced model data, so I’m stumped.
Please let me know if there’s anything I’m missing and thanks!! I will be forever grateful if this works out the way I’m describing.
It took a while I no longer need help!!! I came to a perfect solution using a onetime GDScript preprocess and I have no further questions - I will mark as resolved.
Special thanks to Kio, Badcrow and others in the discord.
You should give the solution to the problem if you’re marking your post as solution. People are just going to be led astray thinking your post contains the solution.
Congrats and cheers !
I’ve come to that problem once and abandoned the project, so knowing the solution would be quite poggers, because I could get into that project again. Please post solution at your earliest convenience.
It is very still buggy at the moment - once it works perfectly I’ll make a separate post detailing what I landed on. If it helps someone, the full code can be public for all I care, lol
Please link it here after you do it, it’ll help a lot for when someone from the future is trying to google a spacial shader to highlight edges and vertices.
Basically the solution was a preprocessor script using MeshDataTool to search the mesh for “sharp” edges on the condition that they are part of only one triangle, since godot’s default import behavior is to split the mesh along those. The sharp edges get encoded into a packedvector3array which is then handed to the shader as a shader parameter, where every two entries are treated as two points of an edge. At runtime I am able to automatically do this for all meshes that need it.
The shader knows to reconstruct the edges from there using a (stolen) point to edge distance function. That distance determines the color in the gradient!!
The part I’m still working on is offsetting the array points for transformations and such, but I’m getting there - the mesh stuff was the hard part, being new territory for me. Once that’s done I might put the full code in a separate post.
That’s cool, but could you provide a snippet of what you did?
A standalone post with more details would go hard, especially if it’s linked here.
Yes I’m definitely doing that with the full code - just taking a minute to clean it up and optimize. It stays intact with in-game transformations using MODEL_MATRIX currently, but my use case also involves compatibility with other vertex shaders, so I’m putting in another matrix for that. There is also some pretty terrible lag at the moment and I think the post will be a chance to fix that.
Will be a standalone showcase post for sure. Tonight or tomorrow depending on how tired I am. Thanks for your patience and I’m still be very glad to help, I haven’t forgotten.