Skip to content

Commit

Permalink
Fix geometry clipping
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 13, 2024
1 parent f98037d commit 7e0791c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ open class DrawableShape protected constructor(): Drawable {
// Use the draw context's modelview projection matrix, transformed to shape local coordinates.
if (drawState.depthOffset != 0.0) {
mvpMatrix.copy(dc.projection).offsetProjectionDepth(drawState.depthOffset)
program.loadClipDistance((mvpMatrix.m[11] / (mvpMatrix.m[10] - 1.0)).toFloat() )
program.loadClipDistance((mvpMatrix.m[11] / (mvpMatrix.m[10] - 1.0)).toFloat())
mvpMatrix.multiplyByMatrix(dc.modelview)
} else {
program.loadClipDistance((dc.projection.m[11] / (dc.projection.m[10] - 1.0f)).toFloat() )
program.loadClipDistance((dc.projection.m[11] / (dc.projection.m[10] - 1.0f)).toFloat())
mvpMatrix.copy(dc.modelviewProjection)
}
mvpMatrix.multiplyByTranslation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ open class TriangleShaderProgram : AbstractShaderProgram() {
cornerX = 2.0 * cornerX - 1.0;
cornerY = 2.0 * cornerY - 1.0;
if(pointAScreen.w < clipDistance) {
pointAScreen = mix(pointAScreen, pointBScreen, (clipDistance - pointAScreen.w)/(pointBScreen.w - pointAScreen.w));
if(pointBScreen.w < clipDistance) {
if(pointAScreen.w > pointBScreen.w) {
pointBScreen = mix(pointBScreen, pointAScreen, clamp((clipDistance - pointBScreen.w)/(pointAScreen.w - pointBScreen.w), 0.0, 1.0));
} else if (pointCScreen.w > pointBScreen.w) {
pointBScreen = mix(pointBScreen, pointCScreen, clamp((clipDistance - pointBScreen.w)/(pointCScreen.w - pointBScreen.w), 0.0, 1.0));
}
}
if(pointCScreen.w < clipDistance) {
pointCScreen = mix(pointCScreen, pointBScreen, (clipDistance - pointCScreen.w)/(pointBScreen.w - pointCScreen.w));
}
pointAScreen = pointAScreen / pointAScreen.w;
pointBScreen = pointBScreen / pointBScreen.w;
pointCScreen = pointCScreen / pointCScreen.w;
pointAScreen.xy = pointAScreen.xy / pointAScreen.w;
pointBScreen.xy = pointBScreen.xy / pointBScreen.w;
pointCScreen.xy = pointCScreen.xy / pointCScreen.w;
vec2 eps = vec2(2.0 / screen.x, 2.0 / screen.y);
eps *= 0.1;
Expand All @@ -75,9 +76,9 @@ open class TriangleShaderProgram : AbstractShaderProgram() {
gl_Position = pointBScreen;
if (miterLength >= miterLengthCutoff && sign(cornerX * dot(miter, point)) > 0.0) {
// trim the corner
gl_Position.xy = gl_Position.xy - (cornerY * cornerX * lineWidth * normalA) / screen.xy;
gl_Position.xy = gl_Position.w * (gl_Position.xy - (cornerY * cornerX * lineWidth * normalA) / screen.xy);
} else {
gl_Position.xy = gl_Position.xy + (cornerY * miter * lineWidth * miterLength) / screen.xy;
gl_Position.xy = gl_Position.w * (gl_Position.xy + (cornerY * miter * lineWidth * miterLength) / screen.xy);
}
}
Expand Down

0 comments on commit 7e0791c

Please sign in to comment.