new PostProcessStage()
Run the post-processing stage on the output of the texture or pre-processing stage in scene rendering.
| Name | Type | Default | Description |
|---|---|---|---|
options.fragmentShader |
String |
The fragment shader to be used. The default sampler2D variables are colorText and depthText. Color texture is the output of a rendered scene or previous stage. Depth texture is the output of rendered scenes. Shaders should contain one or two variables. There is also a vec2 variable named v_textureCoordinates, which can be used to sample textures. |
|
options.uniforms |
Object |
optional
An object whose properties will be used to set the uniformity of shaders. Attributes can be constants or functions. Constants can also be URI, data URI, or HTML elements used as textures. |
|
options.textureScale |
Number | 1.0 |
optional
A number within the range of (0.0, 1.0) used to scale the texture size. A scale of 1.0 will render this post-processing stage as a viewport sized texture. |
options.forcePowerOfTwo |
Boolean | false |
optional
Should the texture size be forced to be a power of 2. The power of 2 is the next power of 2 in the smallest dimension. |
options.sampleMode |
PostProcessStageSampleMode | PostProcessStageSampleMode.NEAREST |
optional
How to sample input color texture. |
options.pixelFormat |
PixelFormat | PixelFormat.RGBA |
optional
Output the color pixel format of the texture. |
options.pixelDatatype |
PixelDatatype | PixelDatatype.UNSIGNED_BYTE |
optional
Output the pixel data type of the texture. |
options.clearColor |
Color | Color.BLACK |
optional
To clear the color of the output texture. |
options.scissorRectangle |
BoundingRectangle |
optional
A rectangle used for scissor testing. |
|
options.name |
String | createGuid() |
optional
The unique name of the subsequent processing stage for reference by other stages in synthesis. If no name is provided, a UID will be generated. |
- See:
-
- PostProcessStageComposite
Throws:
-
-
Options.textureScale must be greater than 0.0 and less than or equal to 1.0.
- Type
- DeveloperError
-
-
-
Options. PixelFormat must be in color format.
- Type
- DeveloperError
-
-
-
When options.tixelDatatype is FLOAT, this WebGL implementation must support the OEs_texture_float extension. Please check 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
-
To clear the color of the output texture.
-
enabledBoolean
-
Whether or not to execute this post-process stage when ready.
-
readonly forcePowerOfTwoNumber
-
Is it mandatory to output texture sizes equal to powers of 2. The power of two will be the power of two next to the minimum size.
-
readonly fragmentShaderString
-
The fragment shader to be used during the post-processing phase.
Shaders must include a sampler declaration for colorText, depthTexture, or both.
The shader must include a vec2 variation declaration for v_textureCoordinates in order to sample texture variables.
-
readonly nameString
-
The unique name of the post-processing stage for reference by other stages in PostProcessStageComposite.
-
readonly pixelDatatypePixelDatatype
-
Output the pixel data type of the texture.
-
readonly pixelFormatPixelFormat
-
Output the color pixel format of the texture.
-
readonly readyBoolean
-
Determine if the post-processing phase is ready. The stage will only be executed when both ready and PostProcessStage # enabled are true. The stage will not be ready while waiting for texture loading.
-
readonly sampleModePostProcessStageSampleMode
-
How to sample the input color texture.
-
readonly scissorRectangleBoundingRectangle
-
BoundingRectangle used for cutting tests. The default bounding rectangle will disable scissor testing.
-
selectedArray
-
Features selected for post-processing applications.
In the fragment shader, use czm_selected to determine whether to apply post-processing stages to the fragment. For example: if (czm_selected(v_textureCoordinates)) { // apply post-process stage } else { gl_FragColor = texture2D(colorTexture, v_textureCordinates); }
-
readonly textureScaleNumber
-
A number within the range of 0.0, 1.0, used to scale the size of the output texture. When the scaling ratio is 1.0, the texture size in the post-processing stage will be the same as the viewport size.
-
readonly uniformsObject
-
Object, whose properties are used to set variables for fragment shaders.
Object property values can be constants or functions. The function will be called every frame before execution in the post-processing stage.
Constant values can also be image URI, data URI, or HTML elements that can be used as textures (such as HTMLImageElement or HTMLCanvasElement).
If the post-processing stage is part of a PostProcessStageComposite that is not concatenated, the constant value can also be the name of another stage in the synthesis. This will set the uniform value to the output texture of the stage with that name.
Methods
-
destroy()
-
Destroy the WebGL resources held by the object. Destroying an object can release WebGL resources deterministically, rather than relying on a garbage collector to destroy the object.
Once the object is destroyed, it cannot be used again; Calling any function other than isDestroyed will result in a Developer Error exception. Therefore, please assign the return value (undefined) to the object using the method shown in the example.
Throws:
-
This object was destroyed, i.e., destroy() was called.
- Type
- DeveloperError
-
-
isDestroyed(){Boolean}
-
If the object has been destroyed, return true; Otherwise, return false.
If the object has been destroyed, it should not be used; Calling any function other than isDestroyed will result in a Developer Error exception.
Returns:
Type Description Boolean If the object has been destroyed, it is true; Otherwise, it is false.