Is it possible to understand in the shader that pixel is on the edge of the geometry?
Or at least understand that pixel on the edge of the triangle?
Maybe ddx()/ddy() can help?
Is it possible to understand in the shader that pixel is on the edge of the geometry?
Or at least understand that pixel on the edge of the triangle?
Maybe ddx()/ddy() can help?
Copyright © 2021 Jogjafile Inc.


Possible but relatively tricky, and you gonna need a geometry shader. They are almost always available in Direct3D: the last GPU with feature level < 11.0 was Intel Sandy Bridge from 2011, computers don’t usually live that long. However, availability in GL and especially GLES varies.
Edges of Triangles
In the geometry shader, generate
float2for each vertex of the triangle, with the values [ 1, 0 ], [ 0, 1 ] and [ 0, 0 ] for the 3 vertices of the triangle.Then in the pixel shader, use the following HLSL function for edge detection, untested:
Edges of Geometry
Your first question is more complicated. One possible approach, add one more vertex attribute of type
DXGI_FORMAT_R8_UINT. Set these bytes to 1 for vertices on the edge of the mesh, 0 for the rest of them.Pass these integers from vertex to geometry shader. There, you can find out which edges of the triangle are on the edge of the geometry:
With that bitmap passed down the graphic pipeline, you can detect pixels on the outer edges of the geometry in the pixel shader:
P.S. I haven’t tested these HLSL functions, but I have used a similar approach in the past, it works.