If comment code : height: 0.
you will find that you get a polygon of different colors, which only changes a height, and the default value of height is 0( At least that’s what the API documentation describes)
2:The polygon in the example will appear or disappear randomly with the distance of the camera. I know the way to prevent this is to set a height attribute to the polygon, but this will lead to material changes.
ex:
Welcome to the community! Thank you for sharing your sandcastle demos.
Regarding your first question, I suggest you check out the following community forum thread. I had a great conversation with @11179 where we discussed color accuracy in 2D. In particular, be sure to look at the second half of the thread.
Regarding your second question, what material changes do you notice when you set the height attribute of your polygon? I have not encountered this issue in the past and was not able to reproduce the bug on my machine. Does anyone from the rest of the community have any suggestions?
Please let me know if you have any other questions or concerns. I am looking forward to learning more about your application.
Hi,
Thank you for your reply on your second question. Firstly, not only the material changes, but also the examples provided. By default, polygon will disappear according to the specific changes of the camera. Secondly, in order to avoid the disappearance caused by the camera distance, I can set a height attribute for polygon graphic with a value of 0, although the API document explains that the default value of height attribute is 0, However, after this setting, the polygon will not disappear, but the material will change. You can see that the color I set is color.cyan. After setting the height, you will get a darker color. The following is a screenshot
Thank you for providing some more information as well as some screenshots. Regarding your second screenshot, it seems like setting the height attribute ensures that the polygon will be visible. There seems to be a consensus among community members that this is the correct way to ensure that the polygon is visible. As for the color accuracy when viewing the polygon in 2D, @11179 came up with a great solution that he outlined in the following post.
The key is that both the height and extrudedHeight affect the color of the asset. @11179 feel free to interject here with more suggestions for @zhouhai1. Let me know if there are any lingering questions or concerns!
@sam.rothstein
I’m very sorry, so the visibility and color can’t be guaranteed to be correct at the same time, right? Let me see the example you mentioned above, which is also true. If I have misunderstood something, please let me know. thank you
While color accuracy and visibility in 2D is a recurring issue in our community, I believe that we have found a workaround. The following sandcastle demos showcase this workaround.
The key is that height and extrudedHeight both impact the color of the object. Let me know if you have any other questions or concerns. Give my suggestions a try and let me know how everything goes!
Hi,@sam.rothstein
Indeed, as you said, from the example you provided, this polygon can maintain the correct color and visibility in 2D.
However, when I raised this question, I did not explain one point. Visibility problems do not occur absolutely. On the premise of correct 2D and color, not all polygons will have visibility errors (possibly due to the position of the polygon or the shape of the polygon, which is just my guess).
In my application scenario, I added some face data of administrative areas, but only one polygon will have visibility problems. So in my last reply, the screenshot showed that some polygons were not displayed correctly.
In the following example, I just modified the position and shape of the polygon you provided, and added a button to ensure that you can successfully locate it after switching to 2D mode. You will find that it does ensure the correctness of color, but the visibility is incorrect. It will appear randomly with the zoom of the camera.
I also encountered the problem of polygons’ visibility and material appearance recently in my project.
Glad to see your discussion with @zhouhai1 here.
However, in this Sandcastle demo you provided in the post:
all polygons look good in 3d and 2.5d mode but when I change to 2d mode, the second line of polygons (without setting “height: 0”) seem to have some visibility issue when I drag the map.
Here is the screen record of what it looks like on my computer. Video.zip (3.5 MB)
I wonder if the visibility issue is related to the hight/extrudehight or timeline properties.
Do you have some good advice for me upon the polygons’ visibility and material appearance issue?
Not sure if you have seen the video I uploaded in the last post, in which the second line of polygons (without setting “height: 0”) seem to have some visibility problem.
To make it more convenient for you, I also uploaded the video to Youtube.
Here is the link: Screen record - YouTube
I am still confused about how it works. Could you please help me figure it out?
I apologize for the delayed response - it has been a very busy week internally at Cesium. Did you get a chance to check out the demo that I shared in my last response? It showcases how to add a single color-accurate polygon to the cesium viewer.
In general, color accuracy and material accuracy in 2D has been a pain point for our community. The following thread provides a nice summary of our findings and links to a lot of important resources.
Let me know if you have any other questions or concerns.
Thanks a lot for your reply.
I did check out the demo you shared in your last response.
And I also tried to change the location of the single polygon to
Cesium.Cartesian3.fromDegreesArray([
100, 0.0,
100, 9.0,
148, 9.0,
148, 0.0,
])
instead of
Cesium.Cartesian3.fromDegreesArray([
0, 0.0,
0, 9.0,
8, 9.0,
8, 0.0,
])
It seems that if the single polygon locates at some certain area, the appearance issue still occurs when I zoom in, zoom out or drag the map.
And most of my study cases, the main cities in China, are located near the certain area.
I think that’s why @zhouhai1 and I have the similar problem.
Thank you very much for your help!
I’ll try to work on the issue, and I’m also looking forward to hearing from you if your community have any progress on this aspect.
Thank you very much for the clarification. I am beginning to understand the subtleties of the issues that you are facing. I think submitting an issue to our GitHub page would be the next logical step. Please submit an issue here:
Once the issue has been submitted, I can help ensure that the issue is reviewed and addressed in a timely manner. I appreciate your patience and am looking forward to getting to the bottom of this bug
I debugged the source code and found something. Whether to set the height or not, the rendering process of polygon is different.
When setting the height, the problem of depth will be involved. In some cases, the shader program will execute discard, which is the reason for the abnormal visible (strictly speaking, some pixels are discarded, not the visibility of the entity).
When the height is not set, the above problem will not occur, but the Phong material will be calculated at the end of the shader program, which is the reason for the change of color shading.
My approach is not to calculate Phong material in 2D scene to avoid different changes of material.I’m not sure if Phong material calculation is necessary in 2D mode and whether it will cause new problems.
@zhouhai1 thank you for the great work! I am grateful that you were able to take a closer look at this topic.
@yujiezhang125 thank you for creating an issue on GitHub. I just tagged a member of our CesiumJS squad. He should take a look at the issue shortly. In the meantime, please give the suggestions outlined by @zhouhai1 a try and let us know if you get the desired result.