Wireframe shader

im wondering how would i tackle making a shader that emulates wireframe mode, but with the normaly perspecive traits of thicker lines up close and thinning far away.

can’t you use glPolygonMode(GL_LINE); ?

A/ lines are the same thickness no matter how far they are from the viewer
B/ i wanna draw the the object normally and then the wireframe over it. if i could do this in a shader it could be achieved in a single pass, using GL_LINE, i will need to draw the object first with GL_FILL and then again with GL_LINE

You could use per-vertex attributes that tell you how far (in world space) you are from each corner of the triangle, and then just shade based on that. You can cram the measurements into three values; either normal xyz, or color rgb, for the three corners of a triangle.

Note that this requires separate geometry from your basic contiguous, smooth mesh, because each vertex needs separate data for each triangle. This is somewhat similar to the case of faceted (rather than smooth) shading with face normals.

You could pass eye space coordinates and also evaluate the barycentric coordinates per fragment, and keep or discard based on how close to the edge the fragment is. You may need store the mesh as individual triangles.

i was hoping to not have to pass any extra data, looks like i have to, oddly enuf i couldnt get it working during my first attempt (i do understand the theory how to do it), so ill run through it with pencil + paper to see wheres its buggering up

had a play round with it a bit more, jwatte i cant really see how your method works, its only gonna let u draw the points and not the lines.
v-man if i understand right with the barycentric coordinates im gonna have to send quite a bit more data pervertex (eg the other vert posiitons)

ideally i was wanting a shader where i could just send the polygons in and the wireframe would just work, unfortunatly i believe i have to do a bit more precompution, like breaking my QUAD strips into plain quads,
anyways i got it working by sending in with each vertice of the quad another vec3.

vertA vec3(0,0)
vertB vec3(1,0);

thus in the interpolated fargment y will be (0+0)/2 == 0 if the fragment lies on the line, thus im doing this in the shader

if ( N_plus_col.x < 0.05 || N_plus_col.y < 0.05 || N_plus_col.x > 0.95 || N_plus_col.y > 0.95 )
f = 1.0;

unfortunatly the lines thicknesses are dependant on the size of the quads, though i suppose if i wanted tto i could susss it out nicer, by basing the number based on the size of the polygon

anyways cheers

its only gonna let u draw the points and not the lines

Assuming you set barycentric u,v = 0 at one vertex, and u=1 and v=1 are the other two vertices, then you want to make the pixel line-colored if u is less than the threshold, or if v is less than the threshold, or if (1-(u+v)) is less than the threshold.

You have to specify barycentric coordinates for each vertex for each face, so it typically has to be separate geometry from your smooth, textured mesh, but I’m pretty sure it works just fine. The hardest part is the generation of the specially-processed geometry (which isn’t terribly hard, just tedious).

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.