A user defined GLSL shader used with
ModelExperimental
as well
as Cesium3DTileset
.
If texture uniforms are used, additional resource management must be done:
-
The
update
function must be called each frame. When a custom shader is passed to aModelExperimental
or aCesium3DTileset
, this step is handled automaticaly -
CustomShader#destroy
must be called when the custom shader is no longer needed to clean up GPU resources properly. The application is responsible for calling this method.
To enable the use of ModelExperimental
in Cesium3DTileset
, set ExperimentalFeatures.enableModelExperimental
to true
or tileset.enableModelExperimental to true
.
See the Custom Shader Guide for more detailed documentation.
Name | Type | Description | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
An object with the following options
|
Example:
const customShader = new CustomShader({
uniforms: {
u_colorIndex: {
type: Cesium.UniformType.FLOAT,
value: 1.0
},
u_normalMap: {
type: Cesium.UniformType.SAMPLER_2D,
value: new Cesium.TextureUniform({
url: "http://example.com/normal.png"
})
}
},
varyings: {
v_selectedColor: Cesium.VaryingType.VEC3
},
vertexShaderText: `
void vertexMain(VertexInput vsInput, inout czm_modelVertexOutput vsOutput) {
v_selectedColor = mix(vsInput.attributes.color_0, vsInput.attributes.color_1, u_colorIndex);
vsOutput.positionMC += 0.1 * vsInput.attributes.normal;
}
`,
fragmentShaderText: `
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
material.normal = texture2D(u_normalMap, fsInput.attributes.texCoord_0);
material.diffuse = v_selectedColor;
}
`
});
Experimental
This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
Methods
Update the value of a uniform declared in the shader
Name | Type | Description |
---|---|---|
uniformName |
String | The GLSL name of the uniform. This must match one of the uniforms declared in the constructor |
value |
Boolean | Number | Cartesian2 | Cartesian3 | Cartesian4 | Matrix2 | Matrix3 | Matrix4 | String | Resource | The new value of the uniform. |