Why is outline calculation 1px less than it should be?

16 Views Asked by At

I'm calculating the outline of a rectangle, which mostly works but the top left segment is 1 pixel less than the bottom right segment.

2px border 1px border

Here is the calculation and the vertex/index data (counterclockwise winding):

let world_position = model * vec4(vertex.position, 0.0, 1.0);
let x = normalize(model * vec4(1.0, 0.0, 0.0, 0.0));
let y = normalize(model * vec4(0.0, 1.0, 0.0, 0.0));
let offset = (x * vertex.normal.x + y * vertex.normal.y) * thickness;
let position = r_camera.view_proj * (world_position + offset);

vertices => [
Vertex { position: [0.0,0.0], normal: [0.0,0.0] },
Vertex { position: [0.0,0.0], normal: [-0.70710677,-0.70710677] },
Vertex { position: [0.0,1.0], normal: [0.0,0.0] },
Vertex { position: [0.0,1.0], normal: [-0.70710677,0.70710677] },
Vertex { position: [1.0,1.0], normal: [0.0,0.0] },
Vertex { position: [1.0,1.0], normal: [0.70710677,0.70710677] },
Vertex { position: [1.0,0.0], normal: [0.0,0.0], },
Vertex { position: [1.0,0.0], normal: [0.70710677,-0.70710677] },
]

indices => [
    0,1,2,
    2,1,3,
    2,3,4,
    4,3,5,
    4,5,6,
    6,5,7,
    6,7,0,
    0,7,1
]

Why is the top-left 1px less and how do I fix it?

0

There are 0 best solutions below