From 5a7c2af3b07dd0af2c7a736c027d1fe8f7abc675 Mon Sep 17 00:00:00 2001 From: Dennis Adams Date: Mon, 27 Jul 2020 16:43:11 +0000 Subject: [PATCH 1/4] force highp in PassThroughDepth, GlobeDepth, PickDepth, ShadowDepthCompare --- Source/Scene/GlobeDepth.js | 2 +- Source/Scene/PickDepth.js | 4 ++-- Source/Shaders/Builtin/Functions/shadowDepthCompare.glsl | 4 ++-- Source/Shaders/PostProcessStages/PassThroughDepth.glsl | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Scene/GlobeDepth.js b/Source/Scene/GlobeDepth.js index 497e4d1ce210..8df6d6e348ae 100644 --- a/Source/Scene/GlobeDepth.js +++ b/Source/Scene/GlobeDepth.js @@ -76,7 +76,7 @@ function executeDebugGlobeDepth(globeDepth, context, passState, useLogDepth) { useLogDepth !== globeDepth._useLogDepth ) { var fsSource = - "uniform sampler2D u_depthTexture;\n" + + "uniform highp sampler2D u_depthTexture;\n" + "varying vec2 v_textureCoordinates;\n" + "void main()\n" + "{\n" + diff --git a/Source/Scene/PickDepth.js b/Source/Scene/PickDepth.js index b9256c278561..87684b0140b9 100644 --- a/Source/Scene/PickDepth.js +++ b/Source/Scene/PickDepth.js @@ -29,7 +29,7 @@ function executeDebugPickDepth(pickDepth, context, passState, useLogDepth) { useLogDepth !== pickDepth._useLogDepth ) { var fsSource = - "uniform sampler2D u_texture;\n" + + "uniform highp sampler2D u_texture;\n" + "varying vec2 v_textureCoordinates;\n" + "void main()\n" + "{\n" + @@ -116,7 +116,7 @@ function updateFramebuffers(pickDepth, context, depthTexture) { function updateCopyCommands(pickDepth, context, depthTexture) { if (!defined(pickDepth._copyDepthCommand)) { var fs = - "uniform sampler2D u_texture;\n" + + "uniform highp sampler2D u_texture;\n" + "varying vec2 v_textureCoordinates;\n" + "void main()\n" + "{\n" + diff --git a/Source/Shaders/Builtin/Functions/shadowDepthCompare.glsl b/Source/Shaders/Builtin/Functions/shadowDepthCompare.glsl index 2125c2b659a9..ea7bec62ecc0 100644 --- a/Source/Shaders/Builtin/Functions/shadowDepthCompare.glsl +++ b/Source/Shaders/Builtin/Functions/shadowDepthCompare.glsl @@ -1,10 +1,10 @@ -float czm_sampleShadowMap(samplerCube shadowMap, vec3 d) +float czm_sampleShadowMap(highp samplerCube shadowMap, vec3 d) { return czm_unpackDepth(textureCube(shadowMap, d)); } -float czm_sampleShadowMap(sampler2D shadowMap, vec2 uv) +float czm_sampleShadowMap(highp sampler2D shadowMap, vec2 uv) { #ifdef USE_SHADOW_DEPTH_TEXTURE return texture2D(shadowMap, uv).r; diff --git a/Source/Shaders/PostProcessStages/PassThroughDepth.glsl b/Source/Shaders/PostProcessStages/PassThroughDepth.glsl index e25361c41d48..e04fce01cdbb 100644 --- a/Source/Shaders/PostProcessStages/PassThroughDepth.glsl +++ b/Source/Shaders/PostProcessStages/PassThroughDepth.glsl @@ -1,4 +1,4 @@ -uniform sampler2D u_depthTexture; +uniform highp sampler2D u_depthTexture; varying vec2 v_textureCoordinates; From ad62186af7c2cec4604bd6cbde7e11363b32d659 Mon Sep 17 00:00:00 2001 From: Dennis Adams Date: Wed, 5 Aug 2020 15:51:07 +0000 Subject: [PATCH 2/4] replace highp by mediump when not supported --- Source/Renderer/ShaderSource.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Renderer/ShaderSource.js b/Source/Renderer/ShaderSource.js index a611e4131a5f..a4955a8197bb 100644 --- a/Source/Renderer/ShaderSource.js +++ b/Source/Renderer/ShaderSource.js @@ -241,6 +241,7 @@ function combineShader(shaderSource, isFragmentShader, context) { precision highp float;\n\ #else\n\ precision mediump float;\n\ + #define highp mediump;\n\ #endif\n\n"; } From e914c5c3c74586645649d685e4813251b256cba6 Mon Sep 17 00:00:00 2001 From: Dennis Adams Date: Wed, 5 Aug 2020 16:10:34 +0000 Subject: [PATCH 3/4] update CHANGES.md --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 7c240ae8a1d3..3efc558a930e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Change Log +### 1.73 - 2020-09-01 + +##### Fixes :wrench: + +- Fixed several artifcats on mobile devices caused by using insufficient precision. [#9064](https://github.com/CesiumGS/cesium/pull/9064) + ### 1.72 - 2020-08-03 ##### Breaking Changes :mega: From 274542b7c77b7a5ce2ad8d0268a9041482ccef7b Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 5 Aug 2020 14:46:42 -0400 Subject: [PATCH 4/4] Remove semicolon and add comment --- Source/Renderer/ShaderSource.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Renderer/ShaderSource.js b/Source/Renderer/ShaderSource.js index a4955a8197bb..9ed28326e831 100644 --- a/Source/Renderer/ShaderSource.js +++ b/Source/Renderer/ShaderSource.js @@ -235,13 +235,16 @@ function combineShader(shaderSource, isFragmentShader, context) { } if (isFragmentShader) { + // If high precision isn't support replace occurrences of highp with mediump + // The highp keyword is not always available on older mobile devices + // See https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#In_WebGL_1_highp_float_support_is_optional_in_fragment_shaders result += "\ #ifdef GL_FRAGMENT_PRECISION_HIGH\n\ precision highp float;\n\ #else\n\ precision mediump float;\n\ - #define highp mediump;\n\ + #define highp mediump\n\ #endif\n\n"; }