PostProcessStage

new Cesium.PostProcessStage(options)

对场景渲染的纹理或上一个后处理阶段的输出运行后处理阶段。
Name Type Description
options Object 具有以下属性的对象:
Name Type Default Description
fragmentShader String 要使用的片段着色器。默认的sampler2D制服是colorTexturedepthTexture。颜色纹理是渲染场景或上一阶段的输出。纹理是渲染场景的输出。着色器应包含一个或两个制服。还有一个vec2,名为v_textureCoordinates,可以用来采样纹理。
uniforms Object optional 其属性将用于设置着色器制服的对象。属性可以是常量值或函数。常量值也可以是用作纹理的URI、数据URI或HTML元素。
textureScale Number 1.0 optional 范围(0.0,1.0]内的数字,用于缩放纹理维度。如果比例为1.0,则会将此后处理阶段渲染为视口大小的纹理。
forcePowerOfTwo Boolean false optional 是否强制纹理尺寸都等于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 : 选项.textureScale必须大于0.0且小于或等于1.0。
  • DeveloperError : 选项.pixelFormat必须是颜色格式。
  • DeveloperError :什么时候选项.像素数据类型是FLOAT,则此WebGL实现必须支持OES_texture_FLOAT扩展。检查context.floatingPointTexture.
Examples:
// Simple stage to change the color
var fs =
    'uniform sampler2D colorTexture;\n' +
    'varying vec2 v_textureCoordinates;\n' +
    'uniform float scale;\n' +
    'uniform vec3 offset;\n' +
    'void main() {\n' +
    '    vec4 color = texture2D(colorTexture, v_textureCoordinates);\n' +
    '    gl_FragColor = vec4(color.rgb * scale + offset, 1.0);\n' +
    '}\n';
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.
var fs =
    'uniform sampler2D colorTexture;\n' +
    'varying vec2 v_textureCoordinates;\n' +
    'uniform vec4 highlight;\n' +
    'void main() {\n' +
    '    vec4 color = texture2D(colorTexture, v_textureCoordinates);\n' +
    '    if (czm_selected()) {\n' +
    '        vec3 highlighted = highlight.a * highlight.rgb + (1.0 - highlight.a) * color.rgb;\n' +
    '        gl_FragColor = vec4(highlighted, 1.0);\n' +
    '    } else { \n' +
    '        gl_FragColor = color;\n' +
    '    }\n' +
    '}\n';
var 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 clearColor : Color

要清除输出纹理的颜色。

enabled : Boolean

准备好后是否执行此后处理阶段。

readonly forcePowerOfTwo : Number

是否强制输出纹理维度都是2的等幂。二的幂将是最小维数的下一次幂。

readonly fragmentShader : String

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

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.

readonly name : String

此后处理阶段的唯一名称,供PostProcessStageComposite中的其他阶段参考。

readonly pixelDatatype : PixelDatatype

输出纹理的像素数据类型。
输出纹理的颜色像素格式。

readonly ready : Boolean

确定此后处理阶段是否为ready。只有在两个就绪时才执行阶段 PostProcessStage#enabledtrue。舞台在等待纹理时将无法就绪 去装载。
如何采样输入颜色纹理。

readonly scissorRectangle : BoundingRectangle

用于剪刀测试的BoundingRectangle。默认的边界矩形将禁用剪切测试。
为应用后期处理而选择的功能。

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 { gl_FragColor = texture2D(colorTexture, v_textureCordinates); }

readonly textureScale : Number

范围(0.0,1.0]内的数字,用于缩放输出纹理维度。如果比例为1.0,则会将此后处理阶段渲染为视口大小的纹理。

readonly uniforms : Object

其属性用于设置碎片着色器的一致性的对象。

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.

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资源,而不是依赖垃圾回收器销毁此对象。

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:
See:

isDestroyed()Boolean

如果此对象已销毁,则返回true;否则返回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;否则为false
See: