Skip to content

Commit

Permalink
push bottom vertices of volumes at far view distances
Browse files Browse the repository at this point in the history
  • Loading branch information
likangning93 committed Jun 11, 2018
1 parent 361c4cd commit fa7075f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
24 changes: 18 additions & 6 deletions Source/Core/GroundPolylineGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,10 @@ define([
var vec2Index = vec2sWriteIndex + j * 2;
var wIndex = vec4Index + 3;

// Encode sidedness of vertex in texture coordinate normalization X
var sidedness = j < 4 ? 1.0 : -1.0;
// Encode sidedness of vertex relative to right plane in texture coordinate normalization X,
// whether vertex is top or bottom of volume in sign/magnitude of normalization Y.
var rightPlaneSide = j < 4 ? 1.0 : -1.0;
var topBottomSide = (j === 2 || j === 3 || j === 6 || j === 7) ? 1.0 : -1.0;

// 3D
Cartesian3.pack(encodedStart.high, startHiAndForwardOffsetX, vec4Index);
Expand All @@ -941,10 +943,15 @@ define([
startNormalAndForwardOffsetZ[wIndex] = forwardOffset.z;

Cartesian3.pack(endPlaneNormal, endNormalAndTextureCoordinateNormalizationX, vec4Index);
endNormalAndTextureCoordinateNormalizationX[wIndex] = texcoordNormalization3DX * sidedness;
endNormalAndTextureCoordinateNormalizationX[wIndex] = texcoordNormalization3DX * rightPlaneSide;

Cartesian3.pack(rightNormal, rightNormalAndTextureCoordinateNormalizationY, vec4Index);
rightNormalAndTextureCoordinateNormalizationY[wIndex] = texcoordNormalization3DY;

var texcoordNormalization = texcoordNormalization3DY * topBottomSide;
if (texcoordNormalization === 0.0 && topBottomSide < 0.0) {
texcoordNormalization = Number.POSITIVE_INFINITY;
}
rightNormalAndTextureCoordinateNormalizationY[wIndex] = texcoordNormalization;

// 2D
if (compute2dAttributes) {
Expand All @@ -963,8 +970,13 @@ define([
offsetAndRight2D[vec4Index + 2] = right2D.x;
offsetAndRight2D[vec4Index + 3] = right2D.y;

texcoordNormalization2D[vec2Index] = texcoordNormalization2DX * sidedness;
texcoordNormalization2D[vec2Index + 1] = texcoordNormalization2DY;
texcoordNormalization2D[vec2Index] = texcoordNormalization2DX * rightPlaneSide;

texcoordNormalization = texcoordNormalization2DY * topBottomSide;
if (texcoordNormalization === 0.0 && topBottomSide < 0.0) {
texcoordNormalization = Number.POSITIVE_INFINITY;
}
texcoordNormalization2D[vec2Index + 1] = texcoordNormalization;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/GroundPolylinePrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ define([
// which causes problems when interpolating log depth from vertices.
// So force computing and writing log depth in the fragment shader.
// Re-enable at far distances to avoid z-fighting.
var vsDefines = ['ENABLE_GL_POSITION_LOG_DEPTH_AT_HEIGHT'];
var vsDefines = ['ENABLE_GL_POSITION_LOG_DEPTH_AT_HEIGHT', 'GLOBE_MINIMUM_ALTITUDE ' + frameState.mapProjection.ellipsoid.minimumRadius.toFixed(1)];
var colorDefine = '';
var materialShaderSource = '';
if (defined(appearance.material)) {
Expand Down
18 changes: 16 additions & 2 deletions Source/Shaders/PolylineShadowVolumeVS.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
attribute vec3 position3DHigh;
attribute vec3 position3DLow;

// In 2D and in 3D, texture coordinate normalization component signs encodes:
// * X sign - sidedness relative to right plane
// * Y sign - is negative OR magnitude is greater than 1.0 if vertex is on bottom of volume
#ifndef COLUMBUS_VIEW_2D
attribute vec4 startHiAndForwardOffsetX;
attribute vec4 startLoAndForwardOffsetY;
Expand Down Expand Up @@ -57,7 +60,8 @@ void main()
endPlaneEC.xyz = czm_normal * vec3(0.0, startEndNormals2D.zw);
endPlaneEC.w = -dot(endPlaneEC.xyz, ecEnd);

v_texcoordNormalizationAndStartEcYZ.xy = vec2(abs(texcoordNormalization2D.x), texcoordNormalization2D.y);
v_texcoordNormalizationAndStartEcYZ.x = abs(texcoordNormalization2D.x);
v_texcoordNormalizationAndStartEcYZ.y = texcoordNormalization2D.y;

#else // COLUMBUS_VIEW_2D
vec3 ecStart = (czm_modelViewRelativeToEye * czm_translateRelativeToEye(startHiAndForwardOffsetX.xyz, startLoAndForwardOffsetY.xyz)).xyz;
Expand All @@ -80,7 +84,8 @@ void main()
v_rightPlaneEC.xyz = czm_normal * rightNormalAndTextureCoordinateNormalizationY.xyz;
v_rightPlaneEC.w = -dot(v_rightPlaneEC.xyz, ecStart);

v_texcoordNormalizationAndStartEcYZ.xy = vec2(abs(endNormalAndTextureCoordinateNormalizationX.w), rightNormalAndTextureCoordinateNormalizationY.w);
v_texcoordNormalizationAndStartEcYZ.x = abs(endNormalAndTextureCoordinateNormalizationX.w);
v_texcoordNormalizationAndStartEcYZ.y = rightNormalAndTextureCoordinateNormalizationY.w;

#endif // COLUMBUS_VIEW_2D

Expand All @@ -105,6 +110,15 @@ void main()
vec3 upOrDown = normalize(cross(v_rightPlaneEC.xyz, planeDirection)); // Points "up" for start plane, "down" at end plane.
vec3 normalEC = normalize(cross(planeDirection, upOrDown)); // In practice, the opposite seems to work too.

// Extrude bottom vertices downward for far view distances, like for GroundPrimitives
upOrDown = cross(forwardDirectionEC, normalEC);
upOrDown = float(czm_sceneMode == czm_sceneMode3D) * upOrDown;
upOrDown = float(v_texcoordNormalizationAndStartEcYZ.y > 1.0 || v_texcoordNormalizationAndStartEcYZ.y < 0.0) * upOrDown;
upOrDown = min(GLOBE_MINIMUM_ALTITUDE, czm_geometricToleranceOverMeter * length(positionRelativeToEye.xyz)) * upOrDown;
positionEC.xyz += upOrDown;

v_texcoordNormalizationAndStartEcYZ.y = czm_branchFreeTernary(v_texcoordNormalizationAndStartEcYZ.y > 1.0, 0.0, abs(v_texcoordNormalizationAndStartEcYZ.y));

// Determine distance along normalEC to push for a volume of appropriate width.
// Make volumes about double pixel width for a conservative fit - in practice the
// extra cost here is minimal compared to the loose volume heights.
Expand Down
18 changes: 13 additions & 5 deletions Specs/Core/GroundPolylineGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ defineSuite([
verifyAttributeValuesIdentical(startHiAndForwardOffsetX);
verifyAttributeValuesIdentical(startLoAndForwardOffsetY);
verifyAttributeValuesIdentical(startNormalAndForwardOffsetZ);
verifyAttributeValuesIdentical(rightNormalAndTextureCoordinateNormalizationY);
verifyAttributeValuesIdentical(startHiLo2D);
verifyAttributeValuesIdentical(offsetAndRight2D);
verifyAttributeValuesIdentical(startEndNormals2D);
Expand Down Expand Up @@ -105,6 +104,19 @@ defineSuite([
expect(Math.sign(values[index])).toEqual(-1.0);
}

// Expect rightNormalAndTextureCoordinateNormalizationY and texcoordNormalization2D.y to encode if the vertex is on the bottom
values = rightNormalAndTextureCoordinateNormalizationY.values;
expect(values[3] > 1.0).toBe(true);
expect(values[1 * 4 + 3] > 1.0).toBe(true);
expect(values[4 * 4 + 3] > 1.0).toBe(true);
expect(values[5 * 4 + 3] > 1.0).toBe(true);

values = texcoordNormalization2D.values;
expect(values[1] > 1.0).toBe(true);
expect(values[1 * 2 + 1] > 1.0).toBe(true);
expect(values[4 * 2 + 1] > 1.0).toBe(true);
expect(values[5 * 2 + 1] > 1.0).toBe(true);

// Line segment geometry is encoded as:
// - start position
// - offset to the end position
Expand Down Expand Up @@ -137,9 +149,7 @@ defineSuite([
expect(Cartesian3.equalsEpsilon(rightNormal3D, new Cartesian3(0.0, 0.0, -1.0), CesiumMath.EPSILON2)).toBe(true);

var texcoordNormalizationX = endNormalAndTextureCoordinateNormalizationX.values[3];
var texcoordNormalizationY = rightNormalAndTextureCoordinateNormalizationY.values[3];
expect(texcoordNormalizationX).toEqualEpsilon(1.0, CesiumMath.EPSILON3);
expect(texcoordNormalizationY).toEqualEpsilon(0.0, CesiumMath.EPSILON3);

// 2D
var projection = new GeographicProjection();
Expand Down Expand Up @@ -174,9 +184,7 @@ defineSuite([
expect(Cartesian3.equalsEpsilon(rightNormal2D, new Cartesian3(0.0, -1.0, 0.0), CesiumMath.EPSILON2)).toBe(true);

texcoordNormalizationX = texcoordNormalization2D.values[0];
texcoordNormalizationY = texcoordNormalization2D.values[1];
expect(texcoordNormalizationX).toEqualEpsilon(1.0, CesiumMath.EPSILON3);
expect(texcoordNormalizationY).toEqualEpsilon(0.0, CesiumMath.EPSILON3);
});

it('does not generate 2D attributes when scene3DOnly is true', function() {
Expand Down

0 comments on commit fa7075f

Please sign in to comment.