new Cesium.CustomShader(options)

A user defined GLSL shader used with Model as well as Cesium3DTileset.

如果使用纹理制服,必须进行额外的资源管理:

  • update 1 函数必须称为每个帧. 当 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 不再需要适当清理 NT 0 资源. 申请 负责使用这种方法.

See the Custom Shader Guide for more detailed documentation.

Name Type Description
options object 具有以下选项的对象
Name Type Default Description
mode CustomShaderMode CustomShaderMode.MODIFY_MATERIAL optional The custom shader mode, which determines how the custom shader code is inserted into the fragment shader.
lightingModel LightingModel optional 照明型号( e.g . PBR 或未亮). 如果存在, 这将覆盖模型的默认照明 .
translucencyMode CustomShaderTranslucencyMode CustomShaderTranslucencyMode.INHERIT optional 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 is CustomShaderTransulcencyMode.INHERIT, the custom shader will render as either opaque or translucent depending on the primitive's material settings.
uniforms Object.<string, UniformSpecifier> optional 用户定义的制服词典. 键是将出现在 GLSL 代码中的统一名称. 值是一个描述统一类型和初始值的对象
varyings Object.<string, VaryingType> optional 用于声明阴影中使用的额外 GLSL 的词典 。 键是将出现在 GLSL 代码中的不同名称. 值是变量的数据类型。 对于每个变化,声明会自动添加到阴影的顶部. 调用者负责在顶点遮蔽处分配一个值,并使用碎片遮蔽处的值.
vertexShaderText string optional 定制顶点阴影器为 NT 0 代码的字符串. 它必须包含一个称为顶点Main的 GLSL . 见预期签字的例子。 如果没有指定,则在计算出的顶点阴影中会跳过自定义顶点阴影阶梯.
fragmentShaderText string optional 自定义片段遮阳器作为 NT 0 代码的字符串. 它必须包含一个称为碎片Main的 NT++1 函数. 见预期签字的例子。 如果没有指定,自定义的片段遮蔽步骤将在计算出来的片段遮蔽器中跳过.
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

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

readonly fragmentShaderText : string

碎片遮蔽器的用户定义 NT% 0 代码

readonly lightingModel : LightingModel

使用自定义阴影器时使用的照明模型. This is used by CustomShaderPipelineStage

readonly mode : CustomShaderMode

确定自定义阴影与总体互动的值 fragment shader. This is used by CustomShaderPipelineStage

readonly translucencyMode : CustomShaderTranslucencyMode

透明模式,它决定如何应用自定义阴影。 如果数值是 NT 0 或 NT 1 ,自定义阴影 将覆盖模型材料中的设置。 如果值为 NT 0 , 根据原始物质的设置,自定义的遮阳器将变成不透明或半透明.
Default Value: CustomShaderTranslucencyMode.INHERIT

readonly uniforms : Object.<string, UniformSpecifier>

用户申报的其他制服.

readonly varyings : Object.<string, VaryingType>

用户宣布的其他差异. This is used by CustomShaderPipelineStage

readonly vertexShaderText : string

顶点遮蔽器的用户定义的 NT% 0 代码

Methods

destroy()

Destroys the WebGL resources held by this object. Destroying an object allows for deterministic 释放 WebGL 资源,而不是依赖垃圾收集器来摧毁此对象.

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:

isDestroyed()boolean

如果此对象被销毁, 返回真实; 否则, 错误 .

If this object was destroyed, it should not be used; calling any function other than isDestroyed will result in a DeveloperError exception.
Returns:
如果此天体被销毁, 则属真; 否则, 属假 .
See:

setUniform(uniformName, value)

更新阴影中宣布的制服值
Name Type Description
uniformName string 校服名称 GLSL . 这一定跟建筑师的制服相符
value boolean | number | Cartesian2 | Cartesian3 | Cartesian4 | Matrix2 | Matrix3 | Matrix4 | string | Resource | TextureUniform 制服的新价值.
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.