wireframe material

I’m working on a wireframe shader, based on an outline shader that I saw on YouTube.

It’s working reasonably well, except that at distances far from the camera there is a white sheen on the poly surfaces, as you can see below:

The material uses an edge-finding algorithm based on a post-process material that uses the depth buffer. As you walk across each pixel, you find its coordinates in the depth buffer and multiply by -4. Then you get the depth values for the adjacent pixels (left, right, top, bottom), and add that to the center, and if it comes out zero, the pixel is black (meaning that the pixels were all in-plane I guess), or if it doesnt then there’s an edge (one of the adjacent pixels was deeper or nearer than the center pixel). Below is the material, and the material function that is used to calculate the depth of each pixel, based on an offset from the central pixel:

Below is the Material Function ScreenTexelDepth:

As you can see from the picture though, it doesn’t seem to work too well at low angles far from the camera.

Anyone have an idea what I could do to rectify this problem?

Thanks

Firstly, thanks for starting this, I was able to make my own shader with this work as a base. I also have a solution: the floor node, this takes any value and pushes it down to the closest integer(in your case 0, aka no light

not answering your question but nice knowledge to have: if you multiply the output of the algorithm by -1 you find all of the inwards facing corners (E.G. where the pillars are touching the ground)

you can add this to the output of the regular algorithm to add lines on every corner. the two outputs will cancel each other out if you don’t do anything, so clamp the *-1 output to 0 to 1, this way the *-1 output doesn’t undo the lines the regular algorithm draws