Class: PostProcessStage

PostProcessStage

new PostProcessStage()

‌在场景渲染的纹理或前序后处理阶段的输出上运行后处理阶段。

Name Type Default Description
options.fragmentShader String

要使用的片段着色器。默认的sampler2D变量是colorTexturedepthTexture。颜色纹理是渲染场景或前一阶段的输出。深度纹理是渲染场景的输出。着色器应该包含一个或两个变量。还有一个vec2变量名为v_textureCoordinates,可用于对纹理进行采样。

options.uniforms Object 可选

一个对象,其属性将用于设置着色器的统一。属性可以是常量或函数。常量也可以是URI、数据URI或用作纹理的HTML元素。

options.textureScale Number 1.0 可选

一个在(0.0,1.0)范围内的数字,用于缩放纹理尺寸。1.0的比例将把这个后期处理阶段渲染成视口大小的纹理。

options.forcePowerOfTwo Boolean false 可选

是否强制纹理尺寸为2的等次幂。2的幂就是最小维度的下一个2的幂。

options.sampleMode PostProcessStageSampleMode PostProcessStageSampleMode.NEAREST 可选

如何采样输入颜色纹理。

options.pixelFormat PixelFormat PixelFormat.RGBA 可选

输出纹理的颜色像素格式。

options.pixelDatatype PixelDatatype PixelDatatype.UNSIGNED_BYTE 可选

输出纹理的像素数据类型。

options.clearColor Color Color.BLACK 可选

要清除输出纹理的颜色。

options.scissorRectangle BoundingRectangle 可选

用于剪刀测试的矩形。

options.name String createGuid() 可选

此后处理阶段的唯一名称,供合成中的其他阶段参考。如果未提供名称,则将生成一个 GUID。

See:
Throws:
  • options.textureScale 必须大于 0.0 且小于或等于 1.0。

    Type
    DeveloperError
  • options.pixelFormat 必须是颜色格式。

    Type
    DeveloperError
  • 当 options.pixelDatatype 为 FLOAT 时,此 WebGL 实现必须支持 OES_texture_float 扩展。请检查 context.floatingPointTexture。

    Type
    DeveloperError
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 SuperMap3D.PostProcessStage({
    fragmentShader : fs,
    uniforms : {
        scale : 1.1,
        offset : function() {
            return new SuperMap3D.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 SuperMap3D.PostProcessStage({
    fragmentShader : fs,
    uniforms : {
        highlight : function() {
            return new SuperMap3D.Color(1.0, 0.0, 0.0, 0.5);
        }
    }
}));
stage.selected = [cesium3DTileFeature];

Members

readonly clearColorColor

要清除输出纹理的颜色。

enabledBoolean

Whether or not to execute this post-process stage when ready.

readonly forcePowerOfTwoNumber

是否强制输出纹理尺寸都等于 2 的幂次。二的幂次将是尺寸最小值的下一个二的幂次。

readonly fragmentShaderString

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

着色器必须包含 colorTexture、depthTexture 或两者的采样器统一声明。

着色器必须包含 v_textureCoordinates 的 vec2 变化声明,以便对纹理变量进行采样。

readonly nameString

后处理阶段的唯一名称,供 PostProcessStageComposite 中的其他阶段引用。

readonly pixelDatatypePixelDatatype

输出纹理的像素数据类型。

readonly pixelFormatPixelFormat

输出纹理的颜色像素格式。

readonly readyBoolean

确定后处理阶段是否已准备就绪。只有当 ready 和 PostProcessStage#enabled 都为 true 时,才会执行舞台。在等待纹理加载时,阶段不会就绪。

readonly sampleModePostProcessStageSampleMode

如何对输入的颜色纹理进行采样。

readonly scissorRectangleBoundingRectangle

用于剪切测试的BoundingRectangle 。默认的包围矩形将禁用剪刀测试。

selectedArray

为应用后处理而选择的特征。

在片段着色器中,使用 czm_selected 来决定是否对该片段应用后处理阶段。例如: if (czm_selected(v_textureCoordinates)) { // apply post-process stage } else { gl_FragColor = texture2D(colorTexture, v_textureCordinates); }

readonly textureScaleNumber

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

readonly uniformsObject

对象,其属性用于设置片段着色器的变量。

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

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

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

Methods

destroy()

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

一旦对象被销毁,就不得再使用;调用 isDestroyed 以外的任何函数都将导致 DeveloperError 异常。 因此,请按照示例中的方法将返回值(undefined)赋值给对象。

See:
Throws:

This object was destroyed, i.e., destroy() was called.

Type
DeveloperError

isDestroyed(){Boolean}

如果该对象已被销毁,则返回 true;否则返回 false。

如果该对象已被销毁,则不应使用;调用 isDestroyed 以外的任何函数都将导致 DeveloperError 异常。

See:
Returns:
Type Description
Boolean 如果该对象已被销毁,则为 true;否则为 false。