Help with wireframe shader

Godot Version

4.3-stable

Question

Heya,
I found the following Shader:

Which is already very good. I was trying to modify it so that is shows only quads so basically “render the fragments close to the hypotenuse (or the longest edge of the triangle) with modelColor and not wireframeColor.” but I have a hard time wrapping my head around it.

here is a visualized idea how it should look in the end.
quadwire

You might be able to look at the shader code in this video, https://www.youtube.com/watch?v=nr5QmPo-HxY&ab_channel=Firnox, to see if you can match what this developer does, but in general quads really don’t exist when rendering happens, just triangles, so deciding on which two triangles ‘should’ be made into a quad visually can be quite tricky especially with models that aren’t as uniform as a sphere. Even with that kind of sphere topology, there are triangles at the poles that might be merged into quads or larger n-gon visual shapes depending on the math you end up with.

There are probably other tricks you can do to get this affect, but it can get pretty tricky very fast, what are you going to use this idea for?

2 Likes

Thank you! I’ll try it out. I’m aware that in the vertex shader “everything is triangles”.

The shader is only used for ingame of simple surfaces like boxes and planes. I think the motivation is pretty much the same as the guy in the video. Especially for blueprint renderings it just looks nicer to have quads instead of triangles.

1 Like

I read into it a bit more and watched the video you linked and the video he made before and now I think it is not possible in Godot.

He uses a feature in Unity where you can access all vertices of a triangle to calculate the length. We don’t have that in Godot. looking at the godot docs for vertex built-ins: there is really only the knowledge about the current vertex.

I take a look at second pass and the state of geometry shaders and if I can work around it, but it doesn’t look like it is possible at all.