diff --git a/CHANGES.md b/CHANGES.md index 7fef41d6a2b3..3e4dd65d9249 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/Source/Renderer/UniformState.js b/Source/Renderer/UniformState.js index d456419789c0..a67ff401fdf1 100644 --- a/Source/Renderer/UniformState.js +++ b/Source/Renderer/UniformState.js @@ -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 = diff --git a/Source/Scene/ClassificationModel.js b/Source/Scene/ClassificationModel.js index e9af83fcb4e4..679fa24cd0b0 100644 --- a/Source/Scene/ClassificationModel.js +++ b/Source/Scene/ClassificationModel.js @@ -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" + @@ -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) { diff --git a/Source/Scene/Primitive.js b/Source/Scene/Primitive.js index 16ce0c782d51..465362ea8836 100644 --- a/Source/Scene/Primitive.js +++ b/Source/Scene/Primitive.js @@ -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; } @@ -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"; diff --git a/Source/Shaders/Builtin/Functions/depthClamp.glsl b/Source/Shaders/Builtin/Functions/depthClamp.glsl new file mode 100644 index 000000000000..f83356a1b56d --- /dev/null +++ b/Source/Shaders/Builtin/Functions/depthClamp.glsl @@ -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; +} diff --git a/Source/Shaders/Builtin/Functions/depthClampFarPlane.glsl b/Source/Shaders/Builtin/Functions/depthClampFarPlane.glsl deleted file mode 100644 index bec295024033..000000000000 --- a/Source/Shaders/Builtin/Functions/depthClampFarPlane.glsl +++ /dev/null @@ -1,27 +0,0 @@ -// emulated noperspective -#ifndef LOG_DEPTH -varying float v_WindowZ; -#endif - -/** - * Clamps a vertex to the far plane. - * - * @name czm_depthClampFarPlane - * @glslFunction - * - * @param {vec4} coords The vertex in clip coordinates. - * @returns {vec4} The vertex clipped to the far plane. - * - * @example - * gl_Position = czm_depthClampFarPlane(czm_modelViewProjection * vec4(position, 1.0)); - * - * @see czm_writeDepthClampedToFarPlane - */ -vec4 czm_depthClampFarPlane(vec4 coords) -{ -#ifndef LOG_DEPTH - v_WindowZ = (0.5 * (coords.z / coords.w) + 0.5) * coords.w; - coords.z = min(coords.z, coords.w); -#endif - return coords; -} diff --git a/Source/Shaders/Builtin/Functions/writeDepthClampedToFarPlane.glsl b/Source/Shaders/Builtin/Functions/writeDepthClamp.glsl similarity index 62% rename from Source/Shaders/Builtin/Functions/writeDepthClampedToFarPlane.glsl rename to Source/Shaders/Builtin/Functions/writeDepthClamp.glsl index bf8cf3209b45..9006fe0a1c99 100644 --- a/Source/Shaders/Builtin/Functions/writeDepthClampedToFarPlane.glsl +++ b/Source/Shaders/Builtin/Functions/writeDepthClamp.glsl @@ -8,18 +8,18 @@ varying float v_WindowZ; * The shader must enable the GL_EXT_frag_depth extension. *

* - * @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 } diff --git a/Source/Shaders/PolylineShadowVolumeFS.glsl b/Source/Shaders/PolylineShadowVolumeFS.glsl index d8b65a80fd0e..2ec1748e963d 100644 --- a/Source/Shaders/PolylineShadowVolumeFS.glsl +++ b/Source/Shaders/PolylineShadowVolumeFS.glsl @@ -83,5 +83,5 @@ void main(void) gl_FragColor = vec4(material.diffuse + material.emission, material.alpha); #endif // PER_INSTANCE_COLOR - czm_writeDepthClampedToFarPlane(); + czm_writeDepthClamp(); } diff --git a/Source/Shaders/PolylineShadowVolumeVS.glsl b/Source/Shaders/PolylineShadowVolumeVS.glsl index 9d17be9312d2..61c9f04ed625 100644 --- a/Source/Shaders/PolylineShadowVolumeVS.glsl +++ b/Source/Shaders/PolylineShadowVolumeVS.glsl @@ -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. diff --git a/Source/Shaders/ShadowVolumeAppearanceFS.glsl b/Source/Shaders/ShadowVolumeAppearanceFS.glsl index 1231a8b0cbae..1b5de0d7eedc 100644 --- a/Source/Shaders/ShadowVolumeAppearanceFS.glsl +++ b/Source/Shaders/ShadowVolumeAppearanceFS.glsl @@ -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; @@ -147,6 +147,6 @@ void main(void) #endif // FLAT #endif // PER_INSTANCE_COLOR - czm_writeDepthClampedToFarPlane(); + czm_writeDepthClamp(); #endif // PICK } diff --git a/Source/Shaders/ShadowVolumeAppearanceVS.glsl b/Source/Shaders/ShadowVolumeAppearanceVS.glsl index 0f2b1c456a3b..8938a0447469 100644 --- a/Source/Shaders/ShadowVolumeAppearanceVS.glsl +++ b/Source/Shaders/ShadowVolumeAppearanceVS.glsl @@ -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); } diff --git a/Source/Shaders/ShadowVolumeFS.glsl b/Source/Shaders/ShadowVolumeFS.glsl index b1af3c3ff493..267d55b6fa87 100644 --- a/Source/Shaders/ShadowVolumeFS.glsl +++ b/Source/Shaders/ShadowVolumeFS.glsl @@ -13,5 +13,5 @@ void main(void) #else gl_FragColor = vec4(1.0); #endif - czm_writeDepthClampedToFarPlane(); + czm_writeDepthClamp(); } diff --git a/Source/Shaders/VectorTileVS.glsl b/Source/Shaders/VectorTileVS.glsl index 6c7a5278e8a3..179f3dc69be4 100644 --- a/Source/Shaders/VectorTileVS.glsl +++ b/Source/Shaders/VectorTileVS.glsl @@ -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)); } diff --git a/Specs/Scene/ShadowVolumeAppearanceSpec.js b/Specs/Scene/ShadowVolumeAppearanceSpec.js index fd5e69eff2a0..deba2c4feb9b 100644 --- a/Specs/Scene/ShadowVolumeAppearanceSpec.js +++ b/Specs/Scene/ShadowVolumeAppearanceSpec.js @@ -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;