# Rendering hard edges via vertex shader

Is there any way to use a vertex shader to draw all edges as hard even though they have been imported from Maya as soft? I’d like to have a hard edge look to my geometry but I would prefer that the vertices not be split into multiple vertices. Seems as though a vertex shader could work but I’m completely new to writing them. I’ve read some of the docs on this but would appreciate guidance in how something like this might be achieved.

As @tanoshimi said a vertex shader just processes each vertex once. So each vertex will have exactly one normal vector. If that vertex is shared by multiple faces / triangles they will be smooth at this point. A vertex shader can’t change this.

However there are ways to get the actual face normal by using the partial derivative functions ddx and ddy in the fragment shader. With those you are able to get two tangent vectors at the current screenspace point which describe your surface plane. Take the crossproduct and normalize it and you have the normal vector of the flat surface. However the derivative functions are quite demanding. You literally are calculating the normal for each fragment.

Something like that:

``````// in the cg fragment shader
float3 x = ddx(IN.pos);  // IN.pos is the screen space vertex position
float3 y = ddy(IN.pos);
float3 normal = normalize(cross(x, y));
``````

It all comes down to if your target platform supports the derivative functions and how they perform on that platform. In most cases it’s more performant to split the vertices.

I don’t think you want a vertex shader - simply try on the “model” tab of the import settings to set “Normals” to “Calculate”, and “Smoothing Angle” to 0"