用户定义的 GLSL 着色器与 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 aModel或一个 or aCesium3DTileset,这一步是自动处理的 , this step is handled automaticaly -
CustomShader#destroy当不再需要自定义着色器时必须调用以正确清理 GPU 资源。应用程序负责调用此方法。 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.
| 名称 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 = texture(u_normalMap, fsInput.attributes.texCoord_0);
material.diffuse = v_selectedColor;
}
`
});
实验性 Experimental
此功能使用的是 3D Tiles 规范的一部分,该规范不是最终版本,并且可能会在没有 Cesium 的标准弃用政策的情况下进行更改。 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.
成员 Members
片段着色器的用户定义 GLSL 代码 The user-defined GLSL code for the fragment shader
readonly lightingModel : LightingModel
使用自定义着色器时要使用的光照模型。这是由 The lighting model to use when using the custom shader. This is used by
CustomShaderPipelineStage
readonly mode : CustomShaderMode
确定自定义着色器如何与整体片段着色器交互的值。这是由 A value determining how the custom shader interacts with the overall fragment shader. This is used by
CustomShaderPipelineStage
readonly translucencyMode : CustomShaderTranslucencyMode
半透明模式,决定如何应用自定义着色器。如果值为 CustomShaderTransulcencyMode.OPAQUE 或 CustomShaderTransulcencyMode.TRANSLUCENT,自定义着色器将覆盖模型材质的设置。如果值为 CustomShaderTransulcencyMode.INHERIT,则自定义着色器将根据图元的材质设置渲染为不透明或半透明。 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.
-
默认值: Default Value:
CustomShaderTranslucencyMode.INHERIT
readonly uniforms : Object.<string, UniformSpecifier>
用户声明的其他制服。 Additional uniforms as declared by the user.
readonly varyings : Object.<string, VaryingType>
用户声明的其他变化。这是由 Additional varyings as declared by the user. This is used by
CustomShaderPipelineStage
顶点着色器的用户定义 GLSL 代码 The user-defined GLSL code for the vertex shader
方法 Methods
销毁该对象持有的 WebGL 资源。销毁对象可以确定性地释放 WebGL 资源,而不是依赖垃圾收集器来销毁该对象。 Destroys the WebGL resources held by this object. Destroying an object allows for deterministic release of WebGL resources, instead of relying on the garbage collector to destroy this object.
一旦对象被销毁,就不应再使用;调用除 Once an object is destroyed, it should not be used; calling any function other than
一旦对象被销毁,就不应再使用;调用除 Once an object is destroyed, it should not be used; calling any function other than
isDestroyed 将导致 will result in a DeveloperError 例外。因此,分配返回值( exception. Therefore, assign the return value (undefined) 到对象,如示例中所做的那样。 ) to the object as done in the example.
抛出: Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: Example:
customShader = customShader && customShader.destroy();
另见: See:
如果该对象被销毁则返回 true;否则为假。 Returns true if this object was destroyed; otherwise, false.
如果该对象被破坏,则不应使用它;调用除 If this object was destroyed, it should not be used; calling any function other than
如果该对象被破坏,则不应使用它;调用除 If this object was destroyed, it should not be used; calling any function other than
isDestroyed 将导致 will result in a DeveloperError exception.
返回: Returns:
如果该对象被销毁,则为 True;否则为假。 True if this object was destroyed; otherwise, false.
另见: See:
更新着色器中声明的统一值 Update the value of a uniform declared in the shader
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
uniformName |
string | 制服的 GLSL 名称。这必须与构造函数中声明的制服之一匹配 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 | TextureUniform | 制服的新价值。 The new value of the uniform. |
