Flatten Cesium3dTileSet

Hello, Recently I want to flatten Cesium3dTileSet, the general idea is to modify the positionMC in CustomShader’s vertexMain, but now the problem is the computed positionWC has low precision and the result is uneven, the code like below:

 void vertexMain(VertexInput vsInput, inout czm_modelVertexOutput vsOutput) {
vec4 worldPosition = czm_model * vec4(vsInput.attributes.positionMC,1.0);
// some code aiming at filtering with worldPostion
// some code change the worldPosition 
vec4 modelPosition=czm_inverseModel * worldPosition;
vsOutput.positionMC=modelPosition.xyz/modelPosition.w;
}

And the result image like this:


The flatten position become uneven.
Is there any solution to solve this problem?

What do you mean by “flattening”? Are you trying to smooth out the surface of the model or something? A before, after and intended image would be helpful. Are you using any terrain model data?

Cheers,

Alex

Hello, thank you for replying.
Flatten means to put the height of some particular area in 3dtileset to a uniform value. Just like it does in How to flat 3DTiles? - Cesium for Unreal - Cesium Community

Today, I have solve the problem. Now it works well like below:
flatten

Thank you for everyone!

1 Like

Can you provide a GitHub/code link or more details on how you solve this? I am trying to do the same but I am unable to do so.

Hello, the solution is to transfer the upvector in camera coordinate to the customshader as a Uniform, then in vertexMain program, use the positionEC to compute ,not the worldPosition, because worldPostion will lowdown the precision, the method to get positionEC is below:

 vec4 viewpos = (czm_modelView * vec4(vsInput.attributes.positionMC, 1.0));
 vec3 viewposvec3=viewpos.xyz/viewpos.w;

Then add this viewposvec3 with a scalarvector , the scalar is height, and the vector is the upvector in camera coordinate uniform.

2 Likes

Hello, How do you apply this method for a particular portion of 3d model? Thanks in advance.

Hello, you could try to add polygon coords in eye coordinates to this vertexMain shaders, then to compute whether or not the frag is in the coords polygon.

do you know how to pass polygon coords to vertexMain shader?

Hello, you could just modify vs , and transform positions to this shader.

thanks, i make it.