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

Disable depth test for labels close to the viewer #5121

Closed
bagnell opened this issue Mar 17, 2017 · 5 comments
Closed

Disable depth test for labels close to the viewer #5121

bagnell opened this issue Mar 17, 2017 · 5 comments

Comments

@bagnell
Copy link
Contributor

bagnell commented Mar 17, 2017

It may be desirable to always have a label be visible, e.g. attached to building or model, when the viewer is close. For example, a label at the center of the milk truck model should be visible at any angle. Now, the depth test on labels causes parts of the label to be occluded.

One option is to have two batches of billboards, one with the depth test enabled and the other would have it disabled. Billboards would need to be rebatched every time the camera moves.

Another option is to move the billboard positions in clip space to the near plane in the vertex shader. Here is an example that works pretty well when added to the end of BillboardCollectionVS.glsl:

float len = length(positionEC.xyz);
if (len > 0.0 && len < 10000.0 && gl_Position.z > -gl_Position.w && gl_Position.z < gl_Position.w) {
    gl_Position.z = -gl_Position.w;
}

The distance 10000.0 should be replaced by a uniform or per-vertex attribute.

@pjcozzi pjcozzi added good first issue An opportunity for first time contributors type - enhancement labels Mar 18, 2017
@pjcozzi
Copy link
Contributor

pjcozzi commented Mar 18, 2017

How did the vertex shader clipping look? OK? If so, this would be a good approach when someone has bandwidth.

@pjcozzi
Copy link
Contributor

pjcozzi commented Mar 18, 2017

Came up when looking at #5083.

@pjcozzi
Copy link
Contributor

pjcozzi commented Mar 19, 2017

Could also fix #2694.

@pjcozzi
Copy link
Contributor

pjcozzi commented Mar 19, 2017

We may actually want this per label. In the following code example, the labels may be very far away and we still do not want to depth test them.

var viewer = new Cesium.Viewer('cesiumContainer');
viewer.scene.globe.depthTestAgainstTerrain = true;
 
var terrainProvider = new Cesium.CesiumTerrainProvider({
    url : '//assets.agi.com/stk-terrain/world',
    requestVertexNormals : true,
                requestWaterMask: true
});
viewer.terrainProvider = terrainProvider;
viewer.scene.terrainProvider = terrainProvider;
 
viewer.entities.add({
    position : Cesium.Cartesian3.fromDegrees(-110, 40.03883),
    point : {
        pixelSize : 15,
        color : Cesium.Color.YELLOW,
        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
    }
});
 
 
viewer.entities.add({
    position : Cesium.Cartesian3.fromDegrees(-100, 35),
    label : {
        text : 'Testing',
        font : '12px Helvetica',
        style : Cesium.LabelStyle.FILL_AND_OUTLINE,
        showBackground: true,
        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
    }
});

@pjcozzi pjcozzi added onramping priority - high and removed good first issue An opportunity for first time contributors labels Mar 19, 2017
@bagnell
Copy link
Contributor Author

bagnell commented Mar 20, 2017

How did the vertex shader clipping look? OK? If so, this would be a good approach when someone has bandwidth.

This check makes sure that it won't be brought to the front if it was clipped by the near or far plane: gl_Position.z > -gl_Position.w && gl_Position.z < gl_Position.w

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants