From 7d716e984fa7f7ebd2547593816344f063d31de4 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 15 Feb 2018 16:37:16 -0500 Subject: [PATCH] Add missing log depth to appearances, point primitives and vector tile polylines. --- .../Appearances/AllMaterialAppearanceFS.glsl | 3 +++ .../Appearances/AllMaterialAppearanceVS.glsl | 2 +- .../Appearances/BasicMaterialAppearanceFS.glsl | 9 ++++++--- .../Appearances/BasicMaterialAppearanceVS.glsl | 6 ++++-- .../EllipsoidSurfaceAppearanceFS.glsl | 17 ++++++++++------- .../EllipsoidSurfaceAppearanceVS.glsl | 6 ++++-- Source/Shaders/PointPrimitiveCollectionFS.glsl | 2 ++ Source/Shaders/PointPrimitiveCollectionVS.glsl | 3 +++ Source/Shaders/Vector3DTilePolylinesVS.glsl | 3 +++ 9 files changed, 36 insertions(+), 15 deletions(-) diff --git a/Source/Shaders/Appearances/AllMaterialAppearanceFS.glsl b/Source/Shaders/Appearances/AllMaterialAppearanceFS.glsl index 672750f1f023..745f0fd43853 100644 --- a/Source/Shaders/Appearances/AllMaterialAppearanceFS.glsl +++ b/Source/Shaders/Appearances/AllMaterialAppearanceFS.glsl @@ -3,6 +3,7 @@ varying vec3 v_normalEC; varying vec3 v_tangentEC; varying vec3 v_bitangentEC; varying vec2 v_st; +varying float v_inverse_depth; void main() { @@ -26,4 +27,6 @@ void main() #else gl_FragColor = czm_phong(normalize(positionToEyeEC), material); #endif + + czm_logDepth(v_inverse_depth); } diff --git a/Source/Shaders/Appearances/AllMaterialAppearanceVS.glsl b/Source/Shaders/Appearances/AllMaterialAppearanceVS.glsl index 6303472f2aaa..6cd5de782fcf 100644 --- a/Source/Shaders/Appearances/AllMaterialAppearanceVS.glsl +++ b/Source/Shaders/Appearances/AllMaterialAppearanceVS.glsl @@ -22,7 +22,7 @@ void main() v_tangentEC = czm_normal * tangent; // tangent in eye coordinates v_bitangentEC = czm_normal * bitangent; // bitangent in eye coordinates v_st = st; - v_inverse_depth = -1.0 / v_positionEC.z; gl_Position = czm_modelViewProjectionRelativeToEye * p; + v_inverse_depth = 1.0 / gl_Position.w; } diff --git a/Source/Shaders/Appearances/BasicMaterialAppearanceFS.glsl b/Source/Shaders/Appearances/BasicMaterialAppearanceFS.glsl index 95be0556c016..b26987f45854 100644 --- a/Source/Shaders/Appearances/BasicMaterialAppearanceFS.glsl +++ b/Source/Shaders/Appearances/BasicMaterialAppearanceFS.glsl @@ -1,9 +1,10 @@ varying vec3 v_positionEC; varying vec3 v_normalEC; +varying float v_inverse_depth; void main() { - vec3 positionToEyeEC = -v_positionEC; + vec3 positionToEyeEC = -v_positionEC; vec3 normalEC = normalize(v_normalEC); #ifdef FACE_FORWARD @@ -14,10 +15,12 @@ void main() materialInput.normalEC = normalEC; materialInput.positionToEyeEC = positionToEyeEC; czm_material material = czm_getMaterial(materialInput); - -#ifdef FLAT + +#ifdef FLAT gl_FragColor = vec4(material.diffuse + material.emission, material.alpha); #else gl_FragColor = czm_phong(normalize(positionToEyeEC), material); #endif + + czm_logDepth(v_inverse_depth); } diff --git a/Source/Shaders/Appearances/BasicMaterialAppearanceVS.glsl b/Source/Shaders/Appearances/BasicMaterialAppearanceVS.glsl index 0d496a877e7c..ea184f96fab0 100644 --- a/Source/Shaders/Appearances/BasicMaterialAppearanceVS.glsl +++ b/Source/Shaders/Appearances/BasicMaterialAppearanceVS.glsl @@ -5,13 +5,15 @@ attribute float batchId; varying vec3 v_positionEC; varying vec3 v_normalEC; +varying float v_inverse_depth; -void main() +void main() { vec4 p = czm_computePosition(); v_positionEC = (czm_modelViewRelativeToEye * p).xyz; // position in eye coordinates v_normalEC = czm_normal * normal; // normal in eye coordinates - + gl_Position = czm_modelViewProjectionRelativeToEye * p; + v_inverse_depth = 1.0 / gl_Position.w; } diff --git a/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceFS.glsl b/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceFS.glsl index 7b1054b4acc9..19db3fbf7a99 100644 --- a/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceFS.glsl +++ b/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceFS.glsl @@ -1,33 +1,36 @@ varying vec3 v_positionMC; varying vec3 v_positionEC; varying vec2 v_st; +varying float v_inverse_depth; void main() { czm_materialInput materialInput; - + vec3 normalEC = normalize(czm_normal3D * czm_geodeticSurfaceNormal(v_positionMC, vec3(0.0), vec3(1.0))); #ifdef FACE_FORWARD normalEC = faceforward(normalEC, vec3(0.0, 0.0, 1.0), -normalEC); #endif - + materialInput.s = v_st.s; materialInput.st = v_st; materialInput.str = vec3(v_st, 0.0); - + // Convert tangent space material normal to eye space materialInput.normalEC = normalEC; materialInput.tangentToEyeMatrix = czm_eastNorthUpToEyeCoordinates(v_positionMC, materialInput.normalEC); - + // Convert view vector to world space - vec3 positionToEyeEC = -v_positionEC; + vec3 positionToEyeEC = -v_positionEC; materialInput.positionToEyeEC = positionToEyeEC; czm_material material = czm_getMaterial(materialInput); - -#ifdef FLAT + +#ifdef FLAT gl_FragColor = vec4(material.diffuse + material.emission, material.alpha); #else gl_FragColor = czm_phong(normalize(positionToEyeEC), material); #endif + + czm_logDepth(v_inverse_depth); } diff --git a/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceVS.glsl b/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceVS.glsl index 1bd13c9a5382..98d73454ce9d 100644 --- a/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceVS.glsl +++ b/Source/Shaders/Appearances/EllipsoidSurfaceAppearanceVS.glsl @@ -6,14 +6,16 @@ attribute float batchId; varying vec3 v_positionMC; varying vec3 v_positionEC; varying vec2 v_st; +varying float v_inverse_depth; -void main() +void main() { vec4 p = czm_computePosition(); v_positionMC = position3DHigh + position3DLow; // position in model coordinates v_positionEC = (czm_modelViewRelativeToEye * p).xyz; // position in eye coordinates v_st = st; - + gl_Position = czm_modelViewProjectionRelativeToEye * p; + v_inverse_depth = 1.0 / gl_Position.w; } diff --git a/Source/Shaders/PointPrimitiveCollectionFS.glsl b/Source/Shaders/PointPrimitiveCollectionFS.glsl index 42b5703fe74d..7cb1e9c997fd 100644 --- a/Source/Shaders/PointPrimitiveCollectionFS.glsl +++ b/Source/Shaders/PointPrimitiveCollectionFS.glsl @@ -2,6 +2,7 @@ varying vec4 v_color; varying vec4 v_outlineColor; varying float v_innerPercent; varying float v_pixelDistance; +varying float v_inverse_depth; #ifdef RENDER_FOR_PICK varying vec4 v_pickColor; @@ -46,4 +47,5 @@ void main() #else gl_FragColor = color; #endif + czm_logDepth(v_inverse_depth); } diff --git a/Source/Shaders/PointPrimitiveCollectionVS.glsl b/Source/Shaders/PointPrimitiveCollectionVS.glsl index 05c576606b8d..abf8f86761d3 100644 --- a/Source/Shaders/PointPrimitiveCollectionVS.glsl +++ b/Source/Shaders/PointPrimitiveCollectionVS.glsl @@ -11,6 +11,7 @@ varying vec4 v_color; varying vec4 v_outlineColor; varying float v_innerPercent; varying float v_pixelDistance; +varying float v_inverse_depth; #ifdef RENDER_FOR_PICK varying vec4 v_pickColor; @@ -180,6 +181,8 @@ void main() v_pixelDistance = 2.0 / totalSize; gl_PointSize = totalSize; + v_inverse_depth = 1.0 / (czm_modelViewProjectionRelativeToEye * p).w; + #ifdef RENDER_FOR_PICK v_pickColor = pickColor; #endif diff --git a/Source/Shaders/Vector3DTilePolylinesVS.glsl b/Source/Shaders/Vector3DTilePolylinesVS.glsl index e30c2559ee63..832ab7d80428 100644 --- a/Source/Shaders/Vector3DTilePolylinesVS.glsl +++ b/Source/Shaders/Vector3DTilePolylinesVS.glsl @@ -6,6 +6,8 @@ attribute float a_batchId; uniform mat4 u_modifiedModelView; +varying float v_inverse_depth; + void main() { float expandDir = expandAndWidth.x; @@ -19,4 +21,5 @@ void main() float angle; vec4 positionWC = getPolylineWindowCoordinatesEC(p, prev, next, expandDir, width, usePrev, angle); gl_Position = czm_viewportOrthographic * positionWC; + v_inverse_depth = 1.0 / (czm_projection * u_modifiedModelView * currentPosition).w; }