How to display underground entity?

I try to show the underground entity through the terrain.

According to translucent-terrain,I have a transparent terrain without blue baseColor, and remove skirt. But I still can not see the underground entity(Or underground part of entity). As shown below.

Set globe.depthTestAgainstTerrain to false, all the entities are displayed. But they cover the terrain/imagery, this is not the effect I want . As shown below.

viewer.scene.globe.depthTestAgainstTerrain = false;

What I need is:

·When imagery.alpha=1.0 (opaque), underground entities are cover by imagery, only overgorund part of entity can be see;

·When imagery.alpha<1.0(transparent),underground entities can be seen through imagery.

Just like this:

(I understand in Cesium 1.40, I can clip some terrain and display underground entities, but i need reserve the terrain and imagery. The only thing I can do is to keep the image translucent, and the underground entities still being rendered.)

Thanks and Regards

This isn’t possible with stock Cesium, but if you are willing to edit the source code further - go to GlobeSurfaceTileProvider.js and change:

command.pass = Pass.GLOBE;

``

to

command.pass = Pass.TRANSLUCENT;


``

You may also need to construct the Viewer with orderIndependentTranslucency set to false for it to look right.

This solution is pretty hacky though so I don't recommend it as a fix. I haven't tested it very thoroughly either.

I included this post in [https://github.com/AnalyticalGraphicsInc/cesium/issues/5665](https://github.com/AnalyticalGraphicsInc/cesium/issues/5665) so we can form a proper solution eventually.

Thanks for the update, I’m glad that actually worked.

在 2017年12月5日星期二 UTC+8上午10:55:49,Zhiwen Li写道:

The rest is fine! I got the effect I want.

Thanks for your help.

在 2017年12月5日星期二 UTC+8上午8:40:13,Sean Lilley写道:
This isn't possible with stock Cesium, but if you are willing to edit the source code further - go to GlobeSurfaceTileProvider.js and change:

command.pass = Pass.GLOBE;
to

command.pass = Pass.TRANSLUCENT;
You may also need to construct the Viewer with orderIndependentTranslucency set to false for it to look right.

This solution is pretty hacky though so I don't recommend it as a fix. I haven't tested it very thoroughly either.

I included this post in https://github.com/AnalyticalGraphicsInc/cesium/issues/5665 so we can form a proper solution eventually.

I try to show the underground entity through the terrain.

According to translucent-terrain,I have a transparent terrain without blue baseColor, and remove skirt. But I still can not see the underground entity(Or underground part of entity). As shown below.

Set globe.depthTestAgainstTerrain to false, all the entities are displayed. But they cover the terrain/imagery, this is not the effect I want . As shown below.viewer.scene.globe.depthTestAgainstTerrain = false;

What I need is:
·When imagery.alpha=1.0 (opaque), underground entities are cover by imagery, only overgorund part of entity can be see;
·When imagery.alpha<1.0(transparent),underground entities can be seen through imagery.

Just like this:

(I understand in Cesium 1.40, I can clip some terrain and display underground entities, but i need reserve the terrain and imagery. The only thing I can do is to keep the image translucent, and the underground entities still being rendered.)

Thanks and Regards

Hi Li, this underground effect looks cool.And this is the effect I also like to fullfill.I was wondering if you can share some ideas or even code.
According your narration in the post,I can not obtain the final effect.I used the cesium 1.40,I set the cesium viewer like the following:

        var terrainProvider = new Cesium.CesiumTerrainProvider({
            url: ‘https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles’,
            requestVertexNormals: true
        });
        
        var viewer = new Cesium.Viewer(‘cesiumContainer’, {
            orderIndependentTranslucency: false,
            baseLayerPicker : false,
            terrainProvider : terrainProvider
            //imageryProvider: bing
        });

Plus,I have change the source code,change "command.pass = Pass.TRANSLUCENT;"
but i can not get your effect,can you help me to figure out the issue.
Thank you very much.

You also need to apply the changes from the branch that was linked: https://github.com/AnalyticalGraphicsInc/cesium/compare/translucent-terrain

在 2017年12月9日星期六 UTC+8上午9:43:18,Sean Lilley写道:

You also need to apply the changes from the branch that was linked: https://github.com/AnalyticalGraphicsInc/cesium/compare/translucent-terrain

On Thursday, December 7, 2017 at 9:47:09 PM UTC-5, ycha...@gmail.com wrote:在 2017年12月5日星期二 UTC+8上午10:55:49,Zhiwen Li写道:

> The rest is fine! I got the effect I want.

>

>

>

>

>

> Thanks for your help.

>

>

> 在 2017年12月5日星期二 UTC+8上午8:40:13,Sean Lilley写道:

> This isn't possible with stock Cesium, but if you are willing to edit the source code further - go to GlobeSurfaceTileProvider.js and change:

>

>

>

>

>

> command.pass = Pass.GLOBE;

> to

>

>

>

>

> command.pass = Pass.TRANSLUCENT;

> You may also need to construct the Viewer with orderIndependentTranslucency set to false for it to look right.

>

>

> This solution is pretty hacky though so I don't recommend it as a fix. I haven't tested it very thoroughly either.

>

>

> I included this post in https://github.com/AnalyticalGraphicsInc/cesium/issues/5665 so we can form a proper solution eventually.

>

>

> I try to show the underground entity through the terrain.

>

>

>

> According to translucent-terrain,I have a transparent terrain without blue baseColor, and remove skirt. But I still can not see the underground entity(Or underground part of entity). As shown below.

>

>

>

>

>

> Set globe.depthTestAgainstTerrain to false, all the entities are displayed. But they cover the terrain/imagery, this is not the effect I want . As shown below.viewer.scene.globe.depthTestAgainstTerrain = false;

>

>

>

>

>

> What I need is:

> ·When imagery.alpha=1.0 (opaque), underground entities are cover by imagery, only overgorund part of entity can be see;

> ·When imagery.alpha<1.0(transparent),underground entities can be seen through imagery.

>

>

> Just like this:

>

>

>

>

>

> (I understand in Cesium 1.40, I can clip some terrain and display underground entities, but i need reserve the terrain and imagery. The only thing I can do is to keep the image translucent, and the underground entities still being rendered.)

>

>

> Thanks and Regards

Hi Li, this underground effect looks cool.And this is the effect I also like to fullfill.I was wondering if you can share some ideas or even code.

According your narration in the post,I can not obtain the final effect.I used the cesium 1.40,I set the cesium viewer like the following:

    var terrainProvider = new Cesium\.CesiumTerrainProvider\(\{

        url: &#39;https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles',

        requestVertexNormals: true

    \}\);

    

    var viewer = new Cesium\.Viewer\(&#39;cesiumContainer&#39;, \{

        orderIndependentTranslucency: false,

        baseLayerPicker : false,

        terrainProvider : terrainProvider

        //imageryProvider: bing

    \}\);

Plus,I have change the source code,change "command.pass = Pass.TRANSLUCENT;"

but i can not get your effect,can you help me to figure out the issue.

Thank you very much.

Thanks,Liley.
I have tried modified the code on translucent-terrain branch,but it seems still in vain, I can not get the effect.

Try this code:

var viewer = new Cesium.Viewer(‘cesiumContainer’, {

skyAtmosphere : false

});

viewer.scene.globe.depthTestAgainstTerrain = false;

viewer.scene.globe.imageryLayers.get(0).alpha = 0.5;

viewer.scene.globe.baseColor = new Cesium.Color(0, 0, 0, 0);

var blueBox = viewer.entities.add({

name : ‘Blue box’,

position: Cesium.Cartesian3.fromDegrees(-114.0, 40.0, 5),

box : {

dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),

material : Cesium.Color.BLUE

}

});

``

The only Cesium code change required is in GlobeSurfaceTileProvider.js, changing

command.pass = Pass.GLOBE;

``

to

command.pass = Pass.TRANSLUCENT;


``

It turns out you don't need to use the old translucent-terrain branch.

This is great Sean, I think this will help with the underwater rendering stuff we were talking about last week as well!

Sean - feel free to delete https://github.com/AnalyticalGraphicsInc/cesium/compare/translucent-terrain if you think it is no longer needed.

Thanks,

Patrick

在 2017年12月12日星期二 UTC+8上午9:03:43,Sean Lilley写道:

Try this code:

var viewer = new Cesium.Viewer('cesiumContainer', {
skyAtmosphere : false
});
viewer.scene.globe.depthTestAgainstTerrain = false;
viewer.scene.globe.imageryLayers.get(0).alpha = 0.5;
viewer.scene.globe.baseColor = new Cesium.Color(0, 0, 0, 0);

var blueBox = viewer.entities.add({
name : 'Blue box',
position: Cesium.Cartesian3.fromDegrees(-114.0, 40.0, 5),
box : {
dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
material : Cesium.Color.BLUE
}
});

The only Cesium code change required is in GlobeSurfaceTileProvider.js, changing

command.pass = Pass.GLOBE;
to

command.pass = Pass.TRANSLUCENT;

It turns out you don't need to use the old translucent-terrain branch.

On Sunday, December 10, 2017 at 8:49:21 PM UTC-5, ycha...@gmail.com wrote:在 2017年12月9日星期六 UTC+8上午9:43:18,Sean Lilley写道:

> You also need to apply the changes from the branch that was linked: https://github.com/AnalyticalGraphicsInc/cesium/compare/translucent-terrain

>

> On Thursday, December 7, 2017 at 9:47:09 PM UTC-5, ycha...@gmail.com wrote:在 2017年12月5日星期二 UTC+8上午10:55:49,Zhiwen Li写道:

>

> > The rest is fine! I got the effect I want.

>

> >

>

> >

>

> >

>

> >

>

> >

>

> > Thanks for your help.

>

> >

>

> >

>

> > 在 2017年12月5日星期二 UTC+8上午8:40:13,Sean Lilley写道:

>

> > This isn't possible with stock Cesium, but if you are willing to edit the source code further - go to GlobeSurfaceTileProvider.js and change:

>

> >

>

> >

>

> >

>

> >

>

> >

>

> > command.pass = Pass.GLOBE;

>

> > to

>

> >

>

> >

>

> >

>

> >

>

> > command.pass = Pass.TRANSLUCENT;

>

> > You may also need to construct the Viewer with orderIndependentTranslucency set to false for it to look right.

>

> >

>

> >

>

> > This solution is pretty hacky though so I don't recommend it as a fix. I haven't tested it very thoroughly either.

>

> >

>

> >

>

> > I included this post in https://github.com/AnalyticalGraphicsInc/cesium/issues/5665 so we can form a proper solution eventually.

>

> >

>

>

> >

>

> > I try to show the underground entity through the terrain.

>

> >

>

> >

>

> >

>

> > According to translucent-terrain,I have a transparent terrain without blue baseColor, and remove skirt. But I still can not see the underground entity(Or underground part of entity). As shown below.

>

> >

>

> >

>

> >

>

> >

>

> >

>

> > Set globe.depthTestAgainstTerrain to false, all the entities are displayed. But they cover the terrain/imagery, this is not the effect I want . As shown below.viewer.scene.globe.depthTestAgainstTerrain = false;

>

> >

>

> >

>

> >

>

> >

>

> >

>

> > What I need is:

>

> > ·When imagery.alpha=1.0 (opaque), underground entities are cover by imagery, only overgorund part of entity can be see;

>

> > ·When imagery.alpha<1.0(transparent),underground entities can be seen through imagery.

>

> >

>

> >

>

> > Just like this:

>

> >

>

> >

>

> >

>

> >

>

> >

>

> > (I understand in Cesium 1.40, I can clip some terrain and display underground entities, but i need reserve the terrain and imagery. The only thing I can do is to keep the image translucent, and the underground entities still being rendered.)

>

> >

>

> >

>

> > Thanks and Regards

>

>

>

> Hi Li, this underground effect looks cool.And this is the effect I also like to fullfill.I was wondering if you can share some ideas or even code.

>

> According your narration in the post,I can not obtain the final effect.I used the cesium 1.40,I set the cesium viewer like the following:

>

>

>

> var terrainProvider = new Cesium.CesiumTerrainProvider({

>

> url: ‘https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles’,

>

> requestVertexNormals: true

>

> });

>

>

>

> var viewer = new Cesium.Viewer('cesiumContainer', {

>

> orderIndependentTranslucency: false,

>

> baseLayerPicker : false,

>

> terrainProvider : terrainProvider

>

> //imageryProvider: bing

>

> });

>

>

>

> Plus,I have change the source code,change "command.pass = Pass.TRANSLUCENT;"

>

> but i can not get your effect,can you help me to figure out the issue.

>

> Thank you very much.

Thanks,Liley.

I have tried modified the code on translucent-terrain branch,but it seems still in vain, I can not get the effect.

Hi,Lilley! Sorry for replying late. I have tried your provided code. It reallllly works. Thanks for illuminating code!
In case, late-comers might need these code, I post the code here.

<code>
        var terrainProvider = new Cesium.CesiumTerrainProvider({
            url: ‘https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles’,
            requestVertexNormals: true
        });
        var viewer = new Cesium.Viewer(‘cesiumContainer’, {
            //skyAtmosphere: false,
            //orderIndependentTranslucency: false,
            baseLayerPicker: false,
            terrainProvider: terrainProvider
        });

        //viewer.scene.globe.depthTestAgainstTerrain = false;
        //change the ugly blue color to black
        viewer.scene.globe.baseColor = new Cesium.Color(0, 0, 0, 0);
        //default is 1
        //viewer.scene.globe.imageryLayers.get(0).alpha = 0.5;

        var blueBox = viewer.entities.add({
            name: 'Blue box',
            position: Cesium.Cartesian3.fromDegrees(-114.0, 40.0, 5),
            box: {
                dimensions: new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
                material: Cesium.Color.BLUE
            }
        });

        viewer.zoomTo(blueBox);
</code>

在 2018年1月18日星期四 UTC+8下午3:50:54,Chao Yin写道:

hi!,

I follow the code you provided, does not work,
you can provide all the code out of it, thank you

You can follow the answer which I posted on the stackoverflow to realize that effect.

If there is any problems, let me know.

发送自 Windows 10 版邮件应用

Sean,

I'm wondering if it's possible to remove the ever-present translucency of the Globe when placing it in the TRANSLUCENT command pass. Note, the location in my demo here is Mount Rushmore, and the Globe is rendered with an active ClippingPlanesCollection. See this image and diff; notice the translucency of the surface of the Globe, even though all alphas are peaked at 1.0:

image: https://i.imgur.com/79fwarJ.gif
diff: https://pastebin.com/qim5FD8L

Some things I learned:
- there are multiple "commands" for the Globe [surface], and not all of them care about clipping planes
- rendering with globe.baseColor with your suggested alpha of 0 creates strangeness
- rendering with scene.debugShowGlobeDepth of true does not work with the Globe in the TRANSLUCENT pass; it seems to have no effect
- rendering with scene.debugShowFrustums of true does not work with the Globe in the TRANSLUCENT pass, it's all black; disabling OIT allows it to work again
- rendering with scene.orderIndependentTranslucency of false disables translucency entirely for the Globe (in the TRANSLUCENT pass)

It's not clear if the "Globe is always semi-transparent" issue is related to multi-frustum, but I would guess not, given that it occurs even when the inspector shows a frustum count of 1.

This animation shows the issue with globe.baseColor with an alpha of 0:

Last, even hardcoding an "finalColor.a = 1.0" / "gl_FragColor.a = 1.0" in the Globe fragment shader still results in a translucent Globe.

This paste shows the general settings I'm using for this scenario:
https://pastebin.com/tAmv2AXP

Thoughts on a way forward? Thanks.

My solution from before is definitely fragile and breaks down in more complicated situations. The globe isn’t designed to be translucent so really the solution above is a lucky hack. Eventually we’ll put work into doing it right.

I tried fixing some of the problems you mentioned but didn’t get too far. I tried a combination of things simultaneously: hardcode an alpha of 0.5 in the shader, turn OIT off, enable blending in GlobeSurfaceTileProvider’s render state. But that all looked the same as with OIT on.

Just to be sure, is setting viewer.scene.globe.depthTestAgainstTerrain to false not enough for your use case? It might help if I know a bit more about the effect you’re striving for.

there are multiple “commands” for the Globe [surface], and not all of them care about clipping planes

Just curious, does this cause any bugs related to clipping planes or is it just an observation?

rendering with globe.baseColor with your suggested alpha of 0 creates strangeness

Yeah that gif is pretty strange. I’m not sure why that’s happening, it seems to work ok with the default globe.

Sorry I don’t have a great answer here. But maybe some of this will generate ideas.

I also encountered the same problem as you, and I want to see the underground entities when the terrain is transparent. can you help me

Yes,I can.
I have solved this problem.

I also hope to solve this problem, and I hope you can provide some solutions or even code, thank you.

Hello, can you help me?