CustomShader

A user defined GLSL shader used with Model 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 a Model or a Cesium3DTileset, 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.

See the Custom Shader Guide for more detailed documentation.

const customShader = new CustomShader({
uniforms: {
u_colorIndex: {
type: UniformType.FLOAT,
value: 1.0
},
u_normalMap: {
type: UniformType.SAMPLER_2D,
value: new TextureUniform({
url: "http://example.com/normal.png"
})
}
},
varyings: {
v_selectedColor: 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 = texture(u_normalMap, fsInput.attributes.texCoord_0);
material.diffuse = v_selectedColor;
}
`
});

Parameters

options

An object with the following options

See also

Constructors

Link copied to clipboard
constructor(options: CustomShader.ConstructorOptions)

Types

Link copied to clipboard

Properties

Link copied to clipboard

The user-defined GLSL code for the fragment shader

Link copied to clipboard

The lighting model to use when using the custom shader. This is used by CustomShaderPipelineStage

Link copied to clipboard

A value determining how the custom shader interacts with the overall fragment shader. This is used by CustomShaderPipelineStage

Link copied to clipboard

The translucency mode, which determines how the custom shader will be applied. If the value is CustomShaderTransulcencyMode.OPAQUE or CustomShaderTransulcencyMode.TRANSLUCENT, the custom shader will override settings from the model's material. If the value isCustomShaderTransulcencyMode.INHERIT, the custom shader will render as either opaque or translucent depending on the primitive's material settings.

Link copied to clipboard

Additional uniforms as declared by the user.

Link copied to clipboard

Additional varyings as declared by the user. This is used by CustomShaderPipelineStage

Link copied to clipboard

The user-defined GLSL code for the vertex shader

Functions

Link copied to clipboard
fun setUniform(uniformName: String, value: Any)

Update the value of a uniform declared in the shader