new PerInstanceColorAppearance()
This allows the use of the same Primitive to draw multiple instances of geometry, each with a different color, as shown in the second example below.
| Name | Type | Default | Description |
|---|---|---|---|
options.flat |
Boolean | false |
optional
When true, flat shading is used in the fragment shader, which means lighting is not considered. |
options.faceForward |
Boolean | !options.closed |
optional
When true, the fragment shader will flip the surface normals as needed to ensure that the normals face the observer and avoid dark spots. This is very useful when coloring both sides of geometry, such as WallGeometry. |
options.translucent |
Boolean | true |
optional
When true, the geometry will appear semi transparent, so PerInstanceColorAppearance # renderState will enable alpha blending. |
options.closed |
Boolean | false |
optional
When true, the geometry will be turned off, so PerInstanceColorAppearance # renderState will enable backside culling. |
options.vertexShaderSource |
String |
optional
Optional GLSL vertex shader source, used to override default vertex shaders. |
|
options.fragmentShaderSource |
String |
optional
Optional GLSL fragment shader source, used to override default fragment shaders. |
|
options.renderState |
RenderState |
optional
Optional presentation state, used to override the default presentation state. |
Example
// A solid white line segment
var primitive = new SuperMap3D.Primitive({
geometryInstances : new SuperMap3D.GeometryInstance({
geometry : new SuperMap3D.SimplePolylineGeometry({
positions : SuperMap3D.Cartesian3.fromDegreesArray([
0.0, 0.0,
5.0, 0.0
])
}),
attributes : {
color : SuperMap3D.ColorGeometryInstanceAttribute.fromColor(new SuperMap3D.Color(1.0, 1.0, 1.0, 1.0))
}
}),
appearance : new SuperMap3D.PerInstanceColorAppearance({
flat : true,
translucent : false
})
});
// Two rectangles in a primitive, each with a different color
var instance = new SuperMap3D.GeometryInstance({
geometry : new SuperMap3D.RectangleGeometry({
rectangle : SuperMap3D.Rectangle.fromDegrees(0.0, 20.0, 10.0, 30.0)
}),
attributes : {
color : new SuperMap3D.Color(1.0, 0.0, 0.0, 0.5)
}
});
var anotherInstance = new SuperMap3D.GeometryInstance({
geometry : new SuperMap3D.RectangleGeometry({
rectangle : SuperMap3D.Rectangle.fromDegrees(0.0, 40.0, 10.0, 50.0)
}),
attributes : {
color : new SuperMap3D.Color(0.0, 0.0, 1.0, 0.5)
}
});
var rectanglePrimitive = new SuperMap3D.Primitive({
geometryInstances : [instance, anotherInstance],
appearance : new SuperMap3D.PerInstanceColorAppearance()
});
Members
-
(static, constant) FLAT_VERTEX_FORMATVertexFormat
-
When PerInstanceColorAppearance # flat is false, all PerInstanceColorAppearance instances compatible with VertexFormat only require one positional property.
-
(static, constant) VERTEX_FORMATVertexFormat
-
VertexFormat vertex format compatible with all PerInstanceColorAppearance instances. This only requires the location and st attribute.
-
readonly closedBoolean
-
When true, the geometry will be turned off, so PerInstanceColorAppearance # renderState will enable backside culling. If the viewer enters the geometry, it will not be visible.
- Default Value: false
readonly faceForwardBoolean
When true, the fragment shader will flip the surface normals as needed to ensure that the normals face the observer and avoid dark spots. This is very useful when coloring both sides of geometry, such as WallGeometry.
- Default Value: true
readonly flatBoolean
When true, flat shading is used in the fragment shader, which means lighting is not considered.
- Default Value: false
readonly fragmentShaderSourceString
GLSL source code for fragment shader.
materialMaterial
This attribute is part of the Appearance interface, but will not be used by PerInstanceColorAppearance as it uses a fully customized fragment shader.
- Default Value: undefined
readonly renderStateObject
The WebGL fixed function state used when rendering geometry.
The rendering state can be explicitly defined when building a PerInstanceColorAppearance instance, or implicitly set through PerInstanceColorAppearance # translated and PerInstanceColorAppearance # closed.
translucentBoolean
When true, the geometry will appear semi transparent, so PerInstanceColorAppearance # renderState will enable alpha blending.
- Default Value: true
readonly vertexFormatVertexFormat
This appearance instance is compatible with VertexFormat vertex format. A geometric object can have more vertex attributes and still be compatible, but it may come at a performance cost, but not less.
readonly vertexShaderSourceString
GLSL source code for vertex shader.
Methods
-
getFragmentShaderSource(){String}
-
Programmatically create a complete GLSL fragment shader source. For PerInstanceColorAppearance, this is from PerInstanceColorAppearance#fragmentShaderSourcećPerInstanceColorAppearance#flat Derived from PerInstanceColorAppearance # faceForward.
Returns:
Type Description String Complete GLSL fragment shader source. -
getRenderState(){Object}
-
Create a presentation state. This is not the final presentation state instance; On the contrary, it can contain a subset of presentation state attributes that are the same as those created in the context.
Returns:
Type Description Object The render state. -
isTranslucent(){Boolean}
-
Determine whether the geometry is semi transparent based on PerInstanceColorAppearance # translucent.
Returns:
Type Description Boolean If the appearance is semi transparent, it is true.