简体   繁体   中英

Custom Point Shader in Autodesk Forge Viewer behaves weirdly with orthograpic Camera

I am using a PointCloud for fast rendering of sprites after this blog post . Everything works fine with the perspective camera. However, if I switch to the orthographic camera via viewer.navigation.toOrthographic() the points' sizes are not calculated correctly. Does anyone know what the issue is or where I might find some clue?

My vertex shader

#if NUM_CUTPLANES > 0
varying highp vec3 vWorldPosition;
#endif
attribute float mVisible;
attribute float mSize;
varying float vMVisible;
uniform float scale;
void main() {
    vMVisible = mVisible;
    
    #if NUM_CUTPLANES > 0
    vec4 _worldPosition = modelMatrix * vec4( position, 1.0 );
    vWorldPosition = _worldPosition.xyz;
    #endif

    vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
    gl_Position = projectionMatrix * mvPosition;
    gl_PointSize = mSize * (scale / (-mvPosition.z) );
}

Zoomed out

正常大小的点

Zoomed in

非常大的点

Zoomed in a little bit more

不再显示积分

The problem is in the last few lines of the fragment shader:

vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
gl_Position = projectionMatrix * mvPosition;
gl_PointSize = mSize * (scale / (-mvPosition.z) );

When using an orthographic projection instead of a perspective projection , the mvPosition (position transformed into the "normalized device coordinates") may have very different values, and so dividing the point size by mvPosition.z may yield unexpected results.

You may need to clamp the final point size by some constants (or by uniforms you provide from your JavaScript code), eg:

gl_PointSize = clamp(mSize * scale / -mvPosition.z, 10.0, 100.0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM