Issue with translucent polygon primitives

In the following code, why are both of my polygons transparent, even though one of them has an alpha value of 1? Is it not possible to have opaque instances when translucent=true on PerInstanceColorAppearance? What if I want to smoothly animate a polygon from transparent to opaque?

The code below runs in sandcastle

var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;

var positions = Cesium.Cartesian3.fromDegreesArray([
    -88.0, 35.0,
    -80.0, 35.0,
    -80.0, 40.0,
    -88.0, 40.0
]);

var positions2 = Cesium.Cartesian3.fromDegreesArray([
    -88.0, 45.0,
    -80.0, 45.0,
    -80.0, 50.0,
    -88.0, 50.0
]);

var geometryInstances = [
  new Cesium.GeometryInstance({
    geometry : Cesium.PolygonGeometry.fromPositions({
        positions : positions,
        height: 1000000,
        extrudedHeight: 1500000,
        vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
    }),
    attributes: {
        color: Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1,1,0,1))
    }
}),
  new Cesium.GeometryInstance({
    geometry : Cesium.PolygonGeometry.fromPositions({
        positions : positions2,
        height: 1000000,
        extrudedHeight: 1500000,
        vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
    }),
    attributes: {
        color: Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1,1,0,.3))
    }
})
]                         

scene.primitives.add(new Cesium.Primitive({
    geometryInstances : geometryInstances,
    appearance : new Cesium.PerInstanceColorAppearance({
        closed : true,
        translucent : true
    })
}));

Ok so this runs deep in Cesium :frowning_face: Check this out, a polygon toggling between alpha 0.9999999 and 1. Seems like the entity logic changes material when alpha changes. I would expect alpha 0.9999999 and 1 to look the same.

var viewer = new Cesium.Viewer("cesiumContainer");
class AniMaterial {
  getType() {
    return 'Color';
  }
  getValue(foo, result) {
    if (!result) {
      result =  {};
    }
    const s = new Date().getSeconds();
    result.color = new Cesium.Color(1,1,0,(s&1)?0.9999999:1);
    return result;
  }
  isConstant = false;
  definitionChanged = new Cesium.Event();
}

var greenPolygon = viewer.entities.add({
  name: "Polygon",
  polygon: {
    hierarchy: Cesium.Cartesian3.fromDegreesArray([
      -108.0,
      42.0,
      -100.0,
      42.0,
      -104.0,
      40.0,
    ]),
    extrudedHeight: 500000.0,
    material: new AniMaterial(),
    closeTop: true,
    closeBottom: false,
  },
});



viewer.zoomTo(viewer.entities); 

@bjorkegeek

I was able to reproduce your results on my machine. Either we have a bug, or the documentation should be more clear.

Do you have any potential fixes in mind? What is your application - maybe there is a temporary workaround?

-Sam