An appearance for GeometryInstance instances with color attributes.
This allows several geometry instances, each with a different color, to
be drawn with the same Primitive as shown in the second example below.
alias PerInstanceColorAppearance
- The options object takes the following properties
- {Boolean} [options.flat=false] When true, flat shading is used in the fragment shader, which means lighting is not taking into account.
- {Boolean} [options.faceForward=!options.closed] When true, the fragment shader flips the surface normal as needed to ensure that the normal faces the viewer to avoid dark spots. This is useful when both sides of a geometry should be shaded like WallGeometry
- {Boolean} [options.translucent=true] When true, the geometry is expected to appear translucent so PerInstanceColorAppearance#renderState has alpha blending enabled.
- {Boolean} [options.closed=false] When true, the geometry is expected to be closed so PerInstanceColorAppearance#renderState has backface culling enabled.
- {String} [options.vertexShaderSource] Optional GLSL vertex shader source to override the default vertex shader.
- {String} [options.fragmentShaderSource] Optional GLSL fragment shader source to override the default fragment shader.
- {RenderState} [options.renderState] Optional render state to override the default render state.
// A solid white line segment
var primitive = new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.SimplePolylineGeometry({
positions : Cesium.Cartesian3.fromDegreesArray([
0.0, 0.0,
5.0, 0.0
])
}),
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 1.0, 1.0, 1.0))
}
}),
appearance : new Cesium.PerInstanceColorAppearance({
flat : true,
translucent : false
})
});
// Two rectangles in a primitive, each with a different color
var instance = new Cesium.GeometryInstance({
geometry : new Cesium.RectangleGeometry({
rectangle : Cesium.Rectangle.fromDegrees(0.0, 20.0, 10.0, 30.0)
}),
attributes : {
color : new Cesium.Color(1.0, 0.0, 0.0, 0.5)
}
});
var anotherInstance = new Cesium.GeometryInstance({
geometry : new Cesium.RectangleGeometry({
rectangle : Cesium.Rectangle.fromDegrees(0.0, 40.0, 10.0, 50.0)
}),
attributes : {
color : new Cesium.Color(0.0, 0.0, 1.0, 0.5)
}
});
var rectanglePrimitive = new Cesium.Primitive({
geometryInstances : [instance, anotherInstance],
appearance : new Cesium.PerInstanceColorAppearance()
});
An appearance for GeometryInstance instances with color attributes. This allows several geometry instances, each with a different color, to be drawn with the same Primitive as shown in the second example below.
alias PerInstanceColorAppearance
- The options object takes the following properties - {Boolean} [options.flat=false] When
true
, flat shading is used in the fragment shader, which means lighting is not taking into account. - {Boolean} [options.faceForward=!options.closed] Whentrue
, the fragment shader flips the surface normal as needed to ensure that the normal faces the viewer to avoid dark spots. This is useful when both sides of a geometry should be shaded like WallGeometry - {Boolean} [options.translucent=true] Whentrue
, the geometry is expected to appear translucent so PerInstanceColorAppearance#renderState has alpha blending enabled. - {Boolean} [options.closed=false] Whentrue
, the geometry is expected to be closed so PerInstanceColorAppearance#renderState has backface culling enabled. - {String} [options.vertexShaderSource] Optional GLSL vertex shader source to override the default vertex shader. - {String} [options.fragmentShaderSource] Optional GLSL fragment shader source to override the default fragment shader. - {RenderState} [options.renderState] Optional render state to override the default render state.// A solid white line segment var primitive = new Cesium.Primitive({ geometryInstances : new Cesium.GeometryInstance({ geometry : new Cesium.SimplePolylineGeometry({ positions : Cesium.Cartesian3.fromDegreesArray([ 0.0, 0.0, 5.0, 0.0 ]) }), attributes : { color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 1.0, 1.0, 1.0)) } }), appearance : new Cesium.PerInstanceColorAppearance({ flat : true, translucent : false }) }); // Two rectangles in a primitive, each with a different color var instance = new Cesium.GeometryInstance({ geometry : new Cesium.RectangleGeometry({ rectangle : Cesium.Rectangle.fromDegrees(0.0, 20.0, 10.0, 30.0) }), attributes : { color : new Cesium.Color(1.0, 0.0, 0.0, 0.5) } }); var anotherInstance = new Cesium.GeometryInstance({ geometry : new Cesium.RectangleGeometry({ rectangle : Cesium.Rectangle.fromDegrees(0.0, 40.0, 10.0, 50.0) }), attributes : { color : new Cesium.Color(0.0, 0.0, 1.0, 0.5) } }); var rectanglePrimitive = new Cesium.Primitive({ geometryInstances : [instance, anotherInstance], appearance : new Cesium.PerInstanceColorAppearance() });