Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ground primitives in orthographic mode #8854

Merged
merged 4 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Fixed a bug where a removed billboard could prevent changing of the `TerrainProvider`. [#8766](https://github.com/CesiumGS/cesium/pull/8766)
- Fixed an issue with 3D Tiles point cloud styling where `${feature.propertyName}` and `${feature["propertyName"]}` syntax would cause a crash. Also fixed an issue where property names with non-alphanumeric characters would crash. [#8785](https://github.com/CesiumGS/cesium/pull/8785)
- Fixed a bug where `DebugCameraPrimitive` was ignoring the near and far planes of the `Camera`. [#8848](https://github.com/CesiumGS/cesium/issues/8848)
- Fixed ground primitives in orthographic mode. [#5110](https://github.com/CesiumGS/cesium/issues/5110)
- Fixed the depth plane in orthographic mode. This improves the quality of polylines and other primitives that are rendered near the horizon. [8858](https://github.com/CesiumGS/cesium/pull/8858)

### 1.69.0 - 2020-05-01
Expand Down
10 changes: 7 additions & 3 deletions Source/Renderer/UniformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -1286,10 +1286,14 @@ UniformState.prototype.update = function (frameState) {
var fov = camera.frustum.fov;
var viewport = this._viewport;
var pixelSizePerMeter;
if (viewport.height > viewport.width) {
pixelSizePerMeter = (Math.tan(0.5 * fov) * 2.0) / viewport.height;
if (defined(fov)) {
if (viewport.height > viewport.width) {
pixelSizePerMeter = (Math.tan(0.5 * fov) * 2.0) / viewport.height;
} else {
pixelSizePerMeter = (Math.tan(0.5 * fov) * 2.0) / viewport.width;
}
} else {
pixelSizePerMeter = (Math.tan(0.5 * fov) * 2.0) / viewport.width;
pixelSizePerMeter = 1.0 / Math.max(viewport.width, viewport.height);
}

this._geometricToleranceOverMeter =
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/ClassificationModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ function createProgram(model) {
uniformDecl +
"void main() {\n" +
computePosition +
" gl_Position = czm_depthClampFarPlane(positionInClipCoords);\n" +
" gl_Position = czm_depthClamp(positionInClipCoords);\n" +
"}\n";
var fs =
"#ifdef GL_EXT_frag_depth\n" +
Expand All @@ -637,7 +637,7 @@ function createProgram(model) {
"void main() \n" +
"{ \n" +
" gl_FragColor = vec4(1.0); \n" +
" czm_writeDepthClampedToFarPlane();\n" +
" czm_writeDepthClamp();\n" +
"}\n";

if (model.extensionsUsed.WEB3D_quantized_attributes) {
Expand Down
12 changes: 2 additions & 10 deletions Source/Scene/Primitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -1132,17 +1132,10 @@ function depthClampVS(vertexShaderSource) {
vertexShaderSource,
"czm_non_depth_clamp_main"
);
// The varying should be surround by #ifdef GL_EXT_frag_depth as an optimization.
// It is not to workaround an issue with Edge:
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12120362/
modifiedVS +=
"varying float v_WindowZ;\n" +
"void main() {\n" +
" czm_non_depth_clamp_main();\n" +
" vec4 position = gl_Position;\n" +
" v_WindowZ = (0.5 * (position.z / position.w) + 0.5) * position.w;\n" +
" position.z = min(position.z, position.w);\n" +
" gl_Position = position;\n" +
" gl_Position = czm_depthClamp(gl_Position);" +
"}\n";
return modifiedVS;
}
Expand All @@ -1153,14 +1146,13 @@ function depthClampFS(fragmentShaderSource) {
"czm_non_depth_clamp_main"
);
modifiedFS +=
"varying float v_WindowZ;\n" +
"void main() {\n" +
" czm_non_depth_clamp_main();\n" +
"#if defined(GL_EXT_frag_depth)\n" +
" #if defined(LOG_DEPTH)\n" +
" czm_writeLogDepth();\n" +
" #else\n" +
" gl_FragDepthEXT = min(v_WindowZ * gl_FragCoord.w, 1.0);\n" +
" czm_writeDepthClamp();\n" +
" #endif\n" +
"#endif\n" +
"}\n";
Expand Down
27 changes: 27 additions & 0 deletions Source/Shaders/Builtin/Functions/depthClamp.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// emulated noperspective
#ifndef LOG_DEPTH
varying float v_WindowZ;
#endif

/**
* Clamps a vertex to the near and far planes.
*
* @name czm_depthClamp
* @glslFunction
*
* @param {vec4} coords The vertex in clip coordinates.
* @returns {vec4} The vertex clipped to the near and far planes.
*
* @example
* gl_Position = czm_depthClamp(czm_modelViewProjection * vec4(position, 1.0));
*
* @see czm_writeDepthClamp
*/
vec4 czm_depthClamp(vec4 coords)
{
#ifndef LOG_DEPTH
v_WindowZ = (0.5 * (coords.z / coords.w) + 0.5) * coords.w;
coords.z = clamp(coords.z, -coords.w, +coords.w);
#endif
return coords;
}
27 changes: 0 additions & 27 deletions Source/Shaders/Builtin/Functions/depthClampFarPlane.glsl

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ varying float v_WindowZ;
* The shader must enable the GL_EXT_frag_depth extension.
* </p>
*
* @name czm_writeDepthClampedToFarPlane
* @name czm_writeDepthClamp
* @glslFunction
*
* @example
* gl_FragColor = color;
* czm_writeDepthClampedToFarPlane();
* czm_writeDepthClamp();
*
* @see czm_depthClampFarPlane
* @see czm_depthClamp
*/
void czm_writeDepthClampedToFarPlane()
void czm_writeDepthClamp()
{
#if defined(GL_EXT_frag_depth) && !defined(LOG_DEPTH)
gl_FragDepthEXT = min(v_WindowZ * gl_FragCoord.w, 1.0);
gl_FragDepthEXT = clamp(v_WindowZ * gl_FragCoord.w, 0.0, 1.0);
#endif
}
2 changes: 1 addition & 1 deletion Source/Shaders/PolylineShadowVolumeFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ void main(void)
gl_FragColor = vec4(material.diffuse + material.emission, material.alpha);
#endif // PER_INSTANCE_COLOR

czm_writeDepthClampedToFarPlane();
czm_writeDepthClamp();
}
2 changes: 1 addition & 1 deletion Source/Shaders/PolylineShadowVolumeVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void main()
#endif

positionEC.xyz += width * normalEC;
gl_Position = czm_depthClampFarPlane(czm_projection * positionEC);
gl_Position = czm_depthClamp(czm_projection * positionEC);

#ifdef ANGLE_VARYING
// Approximate relative screen space direction of the line.
Expand Down
4 changes: 2 additions & 2 deletions Source/Shaders/ShadowVolumeAppearanceFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void main(void)
#ifdef CULL_FRAGMENTS
if (0.0 <= uv.x && uv.x <= 1.0 && 0.0 <= uv.y && uv.y <= 1.0) {
gl_FragColor.a = 1.0; // 0.0 alpha leads to discard from ShaderSource.createPickFragmentShaderSource
czm_writeDepthClampedToFarPlane();
czm_writeDepthClamp();
}
#else // CULL_FRAGMENTS
gl_FragColor.a = 1.0;
Expand Down Expand Up @@ -147,6 +147,6 @@ void main(void)
#endif // FLAT

#endif // PER_INSTANCE_COLOR
czm_writeDepthClampedToFarPlane();
czm_writeDepthClamp();
#endif // PICK
}
2 changes: 1 addition & 1 deletion Source/Shaders/ShadowVolumeAppearanceVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@ void main()
v_color = czm_batchTable_color(batchId);
#endif

gl_Position = czm_depthClampFarPlane(czm_modelViewProjectionRelativeToEye * position);
gl_Position = czm_depthClamp(czm_modelViewProjectionRelativeToEye * position);
}
2 changes: 1 addition & 1 deletion Source/Shaders/ShadowVolumeFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ void main(void)
#else
gl_FragColor = vec4(1.0);
#endif
czm_writeDepthClampedToFarPlane();
czm_writeDepthClamp();
}
2 changes: 1 addition & 1 deletion Source/Shaders/VectorTileVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ uniform mat4 u_modifiedModelViewProjection;

void main()
{
gl_Position = czm_depthClampFarPlane(u_modifiedModelViewProjection * vec4(position, 1.0));
gl_Position = czm_depthClamp(u_modifiedModelViewProjection * vec4(position, 1.0));
}
2 changes: 1 addition & 1 deletion Specs/Scene/ShadowVolumeAppearanceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("Scene/ShadowVolumeAppearance", function () {
"attribute float batchId;\n" +
"void main() {\n" +
" vec4 position = czm_computePosition();\n" +
" gl_Position = czm_depthClampFarPlane(czm_modelViewProjectionRelativeToEye * position);\n" +
" gl_Position = czm_depthClamp(czm_modelViewProjectionRelativeToEye * position);\n" +
"}\n";

var unitSphereEllipsoid = Ellipsoid.UNIT_SPHERE;
Expand Down