PostProcessStage

new Cesium.PostProcessStage(options)

对场景渲染的纹理或前一个后处理阶段的输出执行后处理阶段。
Name Type Description
options object 包含以下属性的对象:
Name Type Default Description
fragmentShader string 要使用的片段着色器。默认的 sampler2D uniform 为 colorTexturedepthTexture。颜色纹理是场景或前一阶段渲染的输出。深度纹理是场景渲染的输出。着色器应包含其中一个或两个 uniform。还有一个名为 v_textureCoordinatesvec2 varying 可用于采样纹理。
uniforms object optional 属性用于设置着色器 uniform 的对象。属性可以是常量值或函数。常量值也可以是 URI、数据 URI 或用作纹理的 HTML 元素。
textureScale number 1.0 optional (0.0, 1.0] 范围内的数值,用于缩放纹理尺寸。缩放比例为 1.0 时,此后处理阶段将渲染到与视口大小相同的纹理。
forcePowerOfTwo boolean false optional 是否强制纹理尺寸均为相等的2的幂。2的幂值将取尺寸最小值后的下一个2的幂。
sampleMode PostProcessStageSampleMode PostProcessStageSampleMode.NEAREST optional 输入颜色纹理的采样方式。
pixelFormat PixelFormat PixelFormat.RGBA optional 输出纹理的颜色像素格式。
pixelDatatype PixelDatatype PixelDatatype.UNSIGNED_BYTE optional 输出纹理的像素数据类型。
clearColor Color Color.BLACK optional 输出纹理的清除颜色。
scissorRectangle BoundingRectangle optional 用于剪刀测试的矩形。
name string createGuid() optional 此后处理阶段的唯一名称,供复合中的其他阶段引用。若未提供名称,将生成一个 GUID。
Throws:
  • DeveloperError : options.textureScale 必须大于 0.0 且小于或等于 1.0。
  • DeveloperError : options.pixelFormat 必须是颜色格式。
  • DeveloperError : 当 options.pixelDatatype 为 FLOAT 时,当前 WebGL 实现必须支持浮点纹理。请检查 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

输出纹理的清除颜色。
准备就绪时是否执行此后处理阶段。

readonly forcePowerOfTwo : number

是否强制输出纹理尺寸均为相等的2的幂。2的幂值将取尺寸最小值后的下一个2的幂。

readonly fragmentShader : string

执行此后处理阶段时要使用的片段着色器。

着色器必须包含 colorTexturedepthTexture 或两者都包含的采样器 uniform 声明。

着色器必须包含用于采样纹理 uniform 的 vec2 varying 声明 v_textureCoordinates

此后处理阶段的唯一名称,供 PostProcessStageComposite 中的其他阶段引用。
输出纹理的像素数据类型。
输出纹理的颜色像素格式。
确定此后处理阶段是否已准备好执行。只有当 readyPostProcessStage#enabled 均为 true 时,阶段才会执行。在等待纹理加载时,阶段将不会准备就绪。
输入颜色纹理的采样方式。
用于剪刀测试的 BoundingRectangle。默认边界矩形将禁用剪刀测试。
为应用后处理而选择的特征。

在片段着色器中,使用 czm_selected 来决定是否对该片段应用后处理阶段。例如: if (czm_selected(v_textureCoordinates)) { // 应用后处理阶段 } else { out_FragColor = texture(colorTexture, v_textureCoordinates); }

readonly textureScale : number

(0.0, 1.0] 范围内的数值,用于缩放输出纹理的尺寸。缩放比例为 1.0 时,此后处理阶段将渲染到与视口大小相同的纹理。

readonly uniforms : object

属性用于设置片段着色器 uniform 的对象。

对象属性值可以是常量或函数。函数将在每帧后处理阶段执行前调用。

常量值也可以是图像的 URI、数据 URI 或可用作纹理的 HTML 元素,如 HTMLImageElement 或 HTMLCanvasElement。

如果此后处理阶段是 PostProcessStageComposite 的一部分且不串行执行,则常量值也可以是在复合中另一个阶段的名称。这将把 uniform 设置为具有该名称阶段的输出纹理。

Methods

销毁此对象持有的 WebGL 资源。销毁对象可以确定性地释放 WebGL 资源,而不是依赖垃圾回收器来销毁此对象。

一旦对象被销毁,就不应再使用;调用除 isDestroyed 之外的任何函数都会导致 DeveloperError 异常。因此, 应像示例中那样将返回值(undefined)赋给该对象。

Throws:
See:
如果此对象已被销毁则返回 true,否则返回 false。

如果此对象已被销毁,则不应再使用;调用除 isDestroyed 之外的任何函数都会导致 DeveloperError 异常。

Returns:
如果此对象已被销毁则返回 true,否则返回 false
See:
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.