How can i show all edges of model?

I am using Monogame 3.5 and i have simple model of cube. I use BasicEffect to draw it. I want it transparent so i use effect.Alpha = 0.5f. Is it possible to show all edges something like on picture?

You can do this by setting the fillmode of the rasterizerstate of your graphicsdevice to WireFrame.

RasterizerState rasterizerState = new RasterizerState();
rasterizerState.FillMode = FillMode.WireFrame;
GraphicsDevice.RasterizerState = rasterizerState;

Note that this will also draw an edge across the faces of your cube since it’s really drawing triangles. I wasn’t sure if this was implemented in MG, so I checked the source and it seems for OpenGL this only works for desktop platforms. I’m guessing it’s not supported in GL ES.

If you want to draw just the edges (so no diagonals) you should try to get the right points from your model data and draw them as lines.

Use a wireframe mode.
If you want to see both wireframe and textures you can draw it in a rendertarget then on top of the rendered model with textures. Or use a specialized pixel shader which renders both in on pass.

how would i go about having a custom pixel shader know when he’s drawing an edge for a different color?

You can get some clues from here:
http://sibgrapi.sid.inpe.br/col/sid.inpe.br/sibgrapi/2010/09.15.18.18/doc/texture-based_wireframe_rendering.pdf
:wink:
The main problem is it duplicates vertices… But if we had geometry shaders, this would be solved.

I would simply render it twice. Once with filled faces at 0.5 alpha, then a second time with wireframe and disable z-test.

If you have a lot of models/complex scene, you can’t afford drawing it 2 times.
In my opinion, in this case a choice has to be made: textured or wireframe only.
But as @Pavol has not specified, I have gone a little off topic.

Ye I don’t really care about wireframe, i was just wondering if there was a good way to find out if I am drawing on an edge to use some in-shader multisampling, coudl have been it was really trivial.

Assuming the UVs go 0 to 1 across the whole face of your triangle/cube. You want to select pixels that are within your UV space distance to 0 or 1. So something like:

float3 on = 1.0 - floor(mod(uv, 1.0 - dist) / dist);

I’m sure there is a simpler way to do this, but this can work too.

I try WireFrame but problems are diagonals lines, because i have also models of cylinders and in that case there is lot of useless lines… I don’t mind to render it twice like you suggested. It is posible to edit this WireFrame and draw only edges (no diagonals)?

The diagonal is an edge. It is a side of a triangle. What you want is to create a list of edges where the two faces sharing that edge have face normals that differ by more than a specified threshold. The difference between the normals would be the dot product of the two face normals, assuming the normals are normalised (they have a length of one). If the dot product is 1, the faces are coplanar so the edge should be hidden. If the dot product is zero, the faces are at 90 degrees, and if the dot product is -1, they are facing opposite directions. What you need to do is determine at what value your threshold will be, and any dot product less than that threshold will be a visible edge and it should be added to the list.

can you help me with same simple code to do this?

+1 for @KonajuGames’s answer.
You should do this at build time in a custom content processor to get better performances, it would be overkill at runtime if the model(s) is(are) very detailed.

A custom content processor is indeed the best way to go about this. But that goes into custom asset processing, asset writers and readers which is a topic for another time.

@Pavol, it’s not really something that a simple code sample could demonstrate, because it is admittedly not a simple task. I think my description of it has covered most of what you need, and in my belief the best way to learn and understand is to try it yourself.

Thank you very much for your help ! I will try my best :slight_smile: