Manual Backface Culling

Hi,

I’m writing a custom shader which includes geometry shader.
I have a mesh with triangle typology. Then I take all the lines out of triangles and recreating the mesh with line typology and render it with the shader. So the shader renders mesh with Line typology but originally the mesh has triangle typology.

Now the question.
How can I make backface culling?
My idea is to save normals of the original mesh in the line points and write some script in shader that compares normals and camera direction. And depending on that ill show the line or not.

So, does anyone know the script how to compare polygon normal and camera direction to define weather the polygon is viewable or not?

Cull Back should take care of this, even if the geometry is created via a geometry shader, assuming your line geometry isn’t camera facing. If it is camera facing then you already know the direction the camera is facing so just do a dot product against that.

@bgolus so even if i have line typology, i still can use built-in culling? like ‘cull on’ ?

shud i care about normals then?
how does it work. i mean how the GPU / Unity knows which lines to cull? coz they are not polygons and cant overlap

Ah, literally lines, not constructing line geometry. Not sure if cull works on those, I haven’t played with line drawing much.

For that you’ll probably want to test the normal at both ends of the line against the view direction and just not add the line. Or you can do it in the pixel shader and alpha or clip() out the lines.

@bgolus

For that you’ll probably want to test the normal at both ends of the line against the view direction and just not add the line
this is the way i made it in the end kinda