Skip to content

Commit

Permalink
improve orthographic rendering
Browse files Browse the repository at this point in the history
better stick billboards when zoomed in
  • Loading branch information
dkoes committed Nov 8, 2024
1 parent 9eb7fbb commit 550c9f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/GLViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export class GLViewer {
if (center < 1)
center = 1;
this.camera.near = center + this.slabNear;
if (this.camera.near < 1)
if (!this.camera.ortho && this.camera.near < 1)
this.camera.near = 1;
this.camera.far = center + this.slabFar;
if (this.camera.near + 1 > this.camera.far)
Expand Down Expand Up @@ -944,6 +944,7 @@ export class GLViewer {
if (parameters.orthographic !== undefined) {
this.camera.ortho = parameters.orthographic;
}
this.setSlabAndFog();
};

public _handleMouseDown(ev) {
Expand Down
19 changes: 14 additions & 5 deletions src/WebGL/shaders/lib/stickimposter/stickimposter.vert
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ void main() {
mvPosition = to;
}
vec3 n = normalize(mvPosition.xyz);
bool isperspective = (projectionMatrix[3][3] == 0.0);
//intersect with the plane defined by the camera looking at the billboard point
if(color.z >= 0.0) { //p1
if(projectionMatrix[3][3] == 0.0) { //perspective
if(isperspective) { //perspective
vec3 pnorm = normalize(p1);
float t = dot(mvPosition.xyz-p1,n)/dot(pnorm,n);
mvPosition.xyz = p1+t*pnorm;
} else { //orthographic
mvPosition.xyz = p1;
}
} else {
if(projectionMatrix[3][3] == 0.0) { //perspective
if(isperspective) { //perspective
vec3 pnorm = normalize(p2);
float t = dot(mvPosition.xyz-p2,n)/dot(pnorm,n);
mvPosition.xyz = p2+t*pnorm;
Expand All @@ -52,9 +53,17 @@ void main() {
}
mult *= -1.0;
}
vec3 cr = normalize(cross(mvPosition.xyz,norm))*radius;
vec3 doublecr = normalize(cross(mvPosition.xyz,cr))*radius;
mvPosition.xyz += mult*(cr + doublecr).xyz;

if(isperspective) { //perspective
vec3 cr = normalize(cross(mvPosition.xyz,norm))*radius;
vec3 doublecr = normalize(cross(mvPosition.xyz,cr))*radius;
mvPosition.xyz += mult*(cr + doublecr).xyz;
} else {
vec3 cr = normalize(cross(vec3(0.0,0.0,-1.0),norm))*radius;
vec3 doublecr = normalize(cross(vec3(0.0,0.0,-1.0),cr))*radius;
mvPosition.xyz += mult*(cr + doublecr).xyz;
}

cposition = mvPosition.xyz;
gl_Position = projectionMatrix * mvPosition;
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ 0 ], 0.0 );
Expand Down

0 comments on commit 550c9f5

Please sign in to comment.