# Silhouette edge deformation problem

Hello, guys!

Hope you are doing well.

The point is I try to implement a silhouette generation.
I calculate all additions for the edge emitting in the XY plane to draw them as rectangles.
But somehow, i don’t understand the way, my rectangles became deformed as a parallelograms or completely disappeared if I using some POV to rendering the item.

The “emit edge” function of geometry shader:

``````void emitEdge(int StartIndex, int EndIndex) {

vec2 p0 = gl_in[StartIndex].gl_Position.xy; // get 2d vector
vec2 p1 = gl_in[EndIndex].gl_Position.xy;

vec2 v = p1 - p0;
vec2 nv = normalize(v);
vec2 alongAddition = nv * texelDiagonal; // calculate addition to make edge a little bit longer
vec2 n = vec2(-nv.y, nv.x) * texelDiagonal; // calculate addition in normal direction to build the rectangle
vec2 newP0 = p0 - alongAddition;  // here make edge longer
vec2 newP1 = p1 + alongAddition;  // here make edge longer

vec4 startPos = gl_in[StartIndex].gl_Position;
vec4 endPos = gl_in[EndIndex].gl_Position;

vec4 p00 = vec4(newP0 + n * startPos.w, startPos.zw);  // build rectangle - line with additions.
vec4 p01 = vec4(newP0 - n * startPos.w, startPos.zw);
vec4 p10 = vec4(newP1 - n * endPos.w, endPos.zw);
vec4 p11 = vec4(newP1 + n * endPos.w, endPos.zw);

emitTriangle(p00, p01, p10); //emit two triangles to build the rectangle
emitTriangle(p00, p10, p11);
}
``````

Here you can see the result:

I can’t understand what is doing on.
I calculate all in the XY plane, I expect the exact rectangles, not parallelograms in the screen view.
Could you help me?

Thanks!)

You can see the angles, them are not 90 degrees at all:

source:

I found the cause.

I just forget for effect of projection component w.

Now it is ok:

So if someone needs to see correct version.
There is:

``````void emitEdge(int StartIndex, int EndIndex) {

vec4 startPos = gl_in[StartIndex].gl_Position;
vec4 endPos = gl_in[EndIndex].gl_Position;
vec2 p0 = startPos.xy / startPos.w;
vec2 p1 = endPos.xy / endPos.w;

vec2 v = p1 - p0;
vec2 nv = normalize(v);
vec2 alongAddition = nv * texelDiagonal;
vec2 n = vec2(-nv.y, nv.x) * texelDiagonal;
vec2 newP0 = p0 - alongAddition;
vec2 newP1 = p1 + alongAddition;

vec4 p00 = vec4((newP0 + n) * startPos.w, startPos.zw);
vec4 p01 = vec4((newP0 - n) * startPos.w, startPos.zw);
vec4 p10 = vec4((newP1 - n) * endPos.w, endPos.zw);
vec4 p11 = vec4((newP1 + n) * endPos.w, endPos.zw);

emitTriangle(p00, p01, p10);
emitTriangle(p00, p10, p11);
}
``````