在場景渲染的紋理或上一個后期處理階段的輸出上運行后期處理階段。
new PostProcessStage(options)
Parameters:
options
(Object)
一個
Name | Description |
---|---|
options.fragmentShader
String
|
要使用的片段明暗器。默認sampler2D 結(jié)構(gòu)為colorTexture 和depthTexture 。顏色紋理是渲染場景或上一階段的輸出。深度紋理是渲染場景的輸出。該明暗器應(yīng)包含一個或兩個結(jié)構(gòu)。還有一個名為v_textureCoordinates 的vec2 變量,可用于對紋理進行采樣。
|
options.uniforms
Object
|
其屬性將用于設(shè)置明暗器結(jié)構(gòu)的對象。屬性可以是常量值或函數(shù)。常量值也可以是用作紋理的uri、data uri或html元素。 |
options.textureScale
Number
default 1.0
|
范圍(0.0,1.0]中用于縮放紋理尺寸的數(shù)字。比例為1.0將使此后期處理階段呈現(xiàn)為視區(qū)大小的紋理。 |
options.forcePowerOfTwo
Boolean
default false
|
是否強制紋理尺寸為二的等冪。二次方的冪將是最小尺寸的二次方的下一次冪。 |
options.sampleMode
PostProcessStageSampleMode
default PostProcessStageSampleMode.NEAREST
|
如何對輸入的顏色紋理進行采樣。 |
options.pixelFormat
PixelFormat
default PixelFormat.RGBA
|
輸出紋理的顏色像素格式。 |
options.pixelDatatype
PixelDatatype
default PixelDatatype.UNSIGNED_BYTE
|
輸出紋理的像素數(shù)據(jù)類型。 |
options.clearColor
Color
default Color.BLACK
|
要清除輸出紋理的顏色。 |
options.scissorRectangle
BoundingRectangle
|
用于剪刀測試的矩形。 |
options.name
String
default createGuid()
|
此后處理階段的唯一名稱,供復合中其他階段參考。如果未提供名稱,將生成一個GUID。 |
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 bmgl.PostProcessStage({
fragmentShader : fs,
uniforms : {
scale : 1.1,
offset : function() {
return new bmgl.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 bmgl.PostProcessStage({
fragmentShader : fs,
uniforms : {
highlight : function() {
return new bmgl.Color(1.0, 0.0, 0.0, 0.5);
}
}
}));
stage.selected = [bm3DTileFeature];
Throws
-
DeveloperError : Options.TextureScale必須大于0.0且小于或等于1.0。
-
DeveloperError : Options.PixelFormat必須是顏色格式。
-
DeveloperError : 當options.pixeldatatype為float時,此WebGL實現(xiàn)必須支持OES紋理float擴展。檢查context.floatingpointtexture。
Members
(readonly) clearColor : Color
要清除輸出紋理的顏色。
enabled : Boolean
準備好后是否執(zhí)行此后期處理階段。
(readonly) forcePowerOfTwo : Number
是否強制輸出紋理尺寸都為二的等冪。二次方的冪將是最小尺寸的二次方的下一次冪。
(readonly) fragmentShader : String
執(zhí)行此后期處理階段時要使用的片段明暗器。
材質(zhì)球必須包含colorTexture
、depthTexture
或兩者的采樣器統(tǒng)一聲明。
材質(zhì)球必須包含vec2
用于v_textureCoordinates
采樣紋理結(jié)構(gòu)的變化聲明。
(readonly) name : String
此后處理階段的唯一名稱,供A
PostProcessStageComposite
中的其他階段參考。
(readonly) pixelDatatype : PixelDatatype
輸出紋理的像素數(shù)據(jù)類型。
(readonly) pixelFormat : PixelFormat
輸出紋理的顏色像素格式。
(readonly) ready : Boolean
(readonly) sampleMode : PostProcessStageSampleMode
如何對輸入的顏色紋理進行采樣。
(readonly) scissorRectangle : BoundingRectangle
BoundingRectangle
用于剪刀測試。默認的邊界矩形將禁用剪刀測試。
selected : Array
為應(yīng)用后期處理選擇的功能。
在片段明暗器中,使用czm_selected
確定是否將后期處理階段應(yīng)用于該片段。例如: if (czm_selected(v_textureCoordinates)) { // apply post-process stage } else { gl_FragColor = texture2D(colorTexture, v_textureCordinates); }
(readonly) textureScale : Number
范圍(0.0,1.0]中用于縮放輸出紋理尺寸的數(shù)字。比例為1.0將使此后期處理階段呈現(xiàn)為視區(qū)大小的紋理。
(readonly) uniforms : Object
其屬性用于設(shè)置片段明暗器的一致性的對象。
對象屬性值可以是常量或函數(shù)。在執(zhí)行后處理階段之前,將調(diào)用每個幀的函數(shù)。
常數(shù)值也可以是圖像的URI、數(shù)據(jù)URI或可用作紋理的HTML元素,例如htmlImageElement或htmlCanvaseElement。
如果此后處理階段是不連續(xù)執(zhí)行的PostProcessStageComposite
的一部分,則常量值也可以是復合中另一個階段的名稱。這將為具有該名稱的階段的輸出紋理設(shè)置統(tǒng)一。
Methods
destroy()
銷毀此對象持有的WebGL資源。銷毀對象允許確定地釋放WebGL資源,而不是依賴垃圾收集器來銷毀此對象。
一旦對象被破壞,就不應(yīng)使用它;調(diào)用除isDestroyed
以外的任何函數(shù)都將導致DeveloperError
異常。因此,將返回值(undefined
)賦給對象,如示例中所述。
Throws
-
DeveloperError : 此對象已被銷毀,即調(diào)用destroy()。
如果此對象被破壞,則返回true;否則返回false。
如果此對象被破壞,則不應(yīng)使用它;調(diào)用除isDestroyed
以外的任何函數(shù)都將導致DeveloperError
異常。