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 Support for subsurface / bathymetry · Issue #5665 · CesiumGS/cesium · GitHub 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.