English中文

PostProcessStage

new Cesium.PostProcessStage(options)

对场景渲染的纹理或上一个后处理阶段的输出运行后处理阶段。 Runs a post-process stage on either the texture rendered by the scene or the output of a previous post-process stage.
名称 Name 类型 Type 说明 Description
options object 具有以下属性的对象: An object with the following properties:
名称 Name 类型 Type 默认值 Default 说明 Description
fragmentShader string 要使用的片段着色器。默认 The fragment shader to use. The default sampler2D 制服是 uniforms are colorTexture and depthTexture。颜色纹理是渲染场景或前一阶段的输出。深度纹理是渲染场景的输出。着色器应包含一种或两种制服。还有一个 . The color texture is the output of rendering the scene or the previous stage. The depth texture is the output from rendering the scene. The shader should contain one or both uniforms. There is also a vec2 不同的命名 varying named v_textureCoordinates 可用于对纹理进行采样。 that can be used to sample the textures.
uniforms object 可选 optional 其属性将用于设置着色器制服的对象。这些属性可以是常量值或函数。常量值也可以是用作纹理的 URI、数据 URI 或 HTML 元素。 An object whose properties will be used to set the shaders uniforms. The properties can be constant values or a function. A constant value can also be a URI, data URI, or HTML element to use as a texture.
textureScale number 1.0 可选 optional (0.0, 1.0] 范围内的数字,用于缩放纹理尺寸。1.0 的缩放比例将将此后处理阶段渲染为视口大小的纹理。 A number in the range (0.0, 1.0] used to scale the texture dimensions. A scale of 1.0 will render this post-process stage to a texture the size of the viewport.
forcePowerOfTwo boolean false 可选 optional 是否强制纹理尺寸均等于 2 的幂。二的幂将是最小维度的下一个二的幂。 Whether or not to force the texture dimensions to be both equal powers of two. The power of two will be the next power of two of the minimum of the dimensions.
sampleMode PostProcessStageSampleMode PostProcessStageSampleMode.NEAREST 可选 optional 如何对输入颜色纹理进行采样。 How to sample the input color texture.
pixelFormat PixelFormat PixelFormat.RGBA 可选 optional 输出纹理的颜色像素格式。 The color pixel format of the output texture.
pixelDatatype PixelDatatype PixelDatatype.UNSIGNED_BYTE 可选 optional 输出纹理的像素数据类型。 The pixel data type of the output texture.
clearColor Color Color.BLACK 可选 optional 清除输出纹理的颜色。 The color to clear the output texture to.
scissorRectangle BoundingRectangle 可选 optional 用于剪刀测试的矩形。 The rectangle to use for the scissor test.
name string createGuid() 可选 optional 此后处理阶段的唯一名称,供组合中的其他阶段参考。如果未提供名称,将生成 GUID。 The unique name of this post-process stage for reference by other stages in a composite. If a name is not supplied, a GUID will be generated.
抛出: Throws:
  • DeveloperError :options.textureScale 必须大于 0.0 且小于或等于 1.0。 : options.textureScale must be greater than 0.0 and less than or equal to 1.0.
  • DeveloperError : options.pixelFormat must be a color format.
  • DeveloperError :当 options.pixelDatatype 为 FLOAT 时,此 WebGL 实现必须支持浮点纹理。检查 context.floatingPointTexture。 : When options.pixelDatatype is FLOAT, this WebGL implementation must support floating point textures. Check context.floatingPointTexture.
示例: Examples:
// Simple stage to change the color
const fs =`
    uniform sampler2D colorTexture;
    in vec2 v_textureCoordinates;
    uniform float scale;
    uniform vec3 offset;
    void main() {
        vec4 color = texture(colorTexture, v_textureCoordinates);
        out_FragColor = vec4(color.rgb * scale + offset, 1.0);
    }`;
scene.postProcessStages.add(new Cesium.PostProcessStage({
    fragmentShader : fs,
    uniforms : {
        scale : 1.1,
        offset : function() {
            return new Cesium.Cartesian3(0.1, 0.2, 0.3);
        }
    }
}));
// Simple stage to change the color of what is selected.
// If czm_selected returns true, the current fragment belongs to geometry in the selected array.
const fs =`
    uniform sampler2D colorTexture;
    in vec2 v_textureCoordinates;
    uniform vec4 highlight;
    void main() {
        vec4 color = texture(colorTexture, v_textureCoordinates);
        if (czm_selected()) {
            vec3 highlighted = highlight.a * highlight.rgb + (1.0 - highlight.a) * color.rgb;
            out_FragColor = vec4(highlighted, 1.0);
        } else {
            out_FragColor = color;
        }
    }`;
const stage = scene.postProcessStages.add(new Cesium.PostProcessStage({
    fragmentShader : fs,
    uniforms : {
        highlight : function() {
            return new Cesium.Color(1.0, 0.0, 0.0, 0.5);
        }
    }
}));
stage.selected = [cesium3DTileFeature];
另见: See:

成员 Members

清除输出纹理的颜色。 The color to clear the output texture to.
准备好后是否执行此后处理阶段。 Whether or not to execute this post-process stage when ready.

readonly forcePowerOfTwo : number

是否强制输出纹理尺寸均等于 2 的幂。二的幂将是最小维度的下一个二的幂。 Whether or not to force the output texture dimensions to be both equal powers of two. The power of two will be the next power of two of the minimum of the dimensions.

readonly fragmentShader : string

执行此后处理阶段时要使用的片段着色器。 The fragment shader to use when execute this post-process stage.

着色器必须包含采样器统一声明 The shader must contain a sampler uniform declaration for colorTexture, depthTexture,或两者兼而有之。 , or both.

着色器必须包含一个 The shader must contain a vec2 不同的声明 varying declaration for v_textureCoordinates 用于采样纹理制服。 for sampling the texture uniforms.

该后处理阶段的唯一名称,供其他阶段参考 The unique name of this post-process stage for reference by other stages in a PostProcessStageComposite.
输出纹理的像素数据类型。 The pixel data type of the output texture.
输出纹理的颜色像素格式。 The color pixel format of the output texture.
确定此后处理阶段是否准备好执行。仅当两者都执行时才执行阶段 Determines if this post-process stage is ready to be executed. A stage is only executed when both ready and PostProcessStage#enabled are true。舞台在等待纹理加载时不会准备好。 . A stage will not be ready while it is waiting on textures to load.
如何对输入颜色纹理进行采样。 How to sample the input color texture.
The BoundingRectangle 用于剪刀测试。默认边界矩形将禁用剪刀测试。 to use for the scissor test. A default bounding rectangle will disable the scissor test.
选择用于应用后处理的特征。 The features selected for applying the post-process.

在片段着色器中,使用 In the fragment shader, use czm_selected 确定是否对该片段应用后处理阶段。例如: to determine whether or not to apply the post-process stage to that fragment. For example: if (czm_selected(v_textureCoordinates)) { // apply post-process stage } else { out_FragColor = texture(colorTexture, v_textureCoordinates); }

readonly textureScale : number

(0.0, 1.0] 范围内的数字,用于缩放输出纹理尺寸。1.0 的缩放比例将将此后处理阶段渲染为视口大小的纹理。 A number in the range (0.0, 1.0] used to scale the output texture dimensions. A scale of 1.0 will render this post-process stage to a texture the size of the viewport.

readonly uniforms : object

其属性用于设置片段着色器的制服的对象。 An object whose properties are used to set the uniforms of the fragment shader.

对象属性值可以是常量或函数。在执行后处理阶段之前,每帧都会调用该函数。 The object property values can be either a constant or a function. The function will be called each frame before the post-process stage is executed.

常量值还可以是图像的 URI、数据 URI 或可用作纹理的 HTML 元素,例如 HTMLImageElement 或 HTMLCanvasElement。 A constant value can also be a URI to an image, a data URI, or an HTML element that can be used as a texture, such as HTMLImageElement or HTMLCanvasElement.

如果此后处理阶段是 If this post-process stage is part of a PostProcessStageComposite 如果不串行执行,则常量值也可以是组合中另一个阶段的名称。这会将统一设置为具有该名称的舞台的输出纹理。 that does not execute in series, the constant value can also be the name of another stage in a composite. This will set the uniform to the output texture the stage with that name.

方法 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 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.
另见: 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 isDestroyed 将导致 will result in a DeveloperError exception.

返回: Returns:
true 如果该物体被摧毁;否则, if this object was destroyed; otherwise, false.
另见: See:
需要帮助吗?获得答案的最快方法是从社区和团队那里获得答案 Need help? The fastest way to get answers is from the community and team on the Cesium Forum.