Parameters:
(Object)
一個(gè)
Name | Description |
---|---|
options.fragmentShader
String
|
要使用的片段明暗器。默認(rèn)sampler2D 結(jié)構(gòu)為colorTexture 和depthTexture 。顏色紋理是渲染場(chǎng)景或上一階段的輸出。深度紋理是渲染場(chǎng)景的輸出。該明暗器應(yīng)包含一個(gè)或兩個(gè)結(jié)構(gòu)。還有一個(gè)名為v_textureCoordinates 的vec2 變量,可用于對(duì)紋理進(jìn)行采樣。
|
options.uniforms
Object
|
其屬性將用于設(shè)置明暗器結(jié)構(gòu)的對(duì)象。屬性可以是常量值或函數(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
|
是否強(qiáng)制紋理尺寸為二的等冪。二次方的冪將是最小尺寸的二次方的下一次冪。 |
options.sampleMode
PostProcessStageSampleMode
default PostProcessStageSampleMode.NEAREST
|
如何對(duì)輸入的顏色紋理進(jìn)行采樣。 |
options.pixelFormat
PixelFormat
default PixelFormat.RGBA
|
輸出紋理的顏色像素格式。 |
options.pixelDatatype
PixelDatatype
default PixelDatatype.UNSIGNED_BYTE
|
輸出紋理的像素?cái)?shù)據(jù)類型。 |
options.clearColor
Color
default Color.BLACK
|
要清除輸出紋理的顏色。 |
options.scissorRectangle
BoundingRectangle
|
用于剪刀測(cè)試的矩形。 |
options.name
String
default createGuid()
|
此后處理階段的唯一名稱,供復(fù)合中其他階段參考。如果未提供名稱,將生成一個(gè)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 : 當(dāng)options.pixeldatatype為float時(shí),此WebGL實(shí)現(xiàn)必須支持OES紋理float擴(kuò)展。檢查context.floatingpointtexture。
Members
(readonly) clearColor : Color
enabled : Boolean
(readonly) forcePowerOfTwo : Number
(readonly) fragmentShader : String
材質(zhì)球必須包含colorTexture
、depthTexture
或兩者的采樣器統(tǒng)一聲明。
材質(zhì)球必須包含vec2
用于v_textureCoordinates
采樣紋理結(jié)構(gòu)的變化聲明。
(readonly) name : String
PostProcessStageComposite
中的其他階段參考。
(readonly) pixelDatatype : PixelDatatype
(readonly) pixelFormat : PixelFormat
(readonly) ready : Boolean
ready
和PostProcessStage#enabled
都是true
時(shí)執(zhí)行。在等待加載紋理時(shí),階段將不準(zhǔn)備就緒。
(readonly) sampleMode : PostProcessStageSampleMode
(readonly) scissorRectangle : BoundingRectangle
BoundingRectangle
用于剪刀測(cè)試。默認(rèn)的邊界矩形將禁用剪刀測(cè)試。
selected : Array
在片段明暗器中,使用czm_selected
確定是否將后期處理階段應(yīng)用于該片段。例如: if (czm_selected(v_textureCoordinates)) { // apply post-process stage } else { gl_FragColor = texture2D(colorTexture, v_textureCordinates); }
(readonly) textureScale : Number
(readonly) uniforms : Object
對(duì)象屬性值可以是常量或函數(shù)。在執(zhí)行后處理階段之前,將調(diào)用每個(gè)幀的函數(shù)。
常數(shù)值也可以是圖像的URI、數(shù)據(jù)URI或可用作紋理的HTML元素,例如htmlImageElement或htmlCanvaseElement。
如果此后處理階段是不連續(xù)執(zhí)行的PostProcessStageComposite
的一部分,則常量值也可以是復(fù)合中另一個(gè)階段的名稱。這將為具有該名稱的階段的輸出紋理設(shè)置統(tǒng)一。
Methods
destroy()一旦對(duì)象被破壞,就不應(yīng)使用它;調(diào)用除isDestroyed
以外的任何函數(shù)都將導(dǎo)致DeveloperError
異常。因此,將返回值(undefined
)賦給對(duì)象,如示例中所述。
Throws
-
DeveloperError : 此對(duì)象已被銷毀,即調(diào)用destroy()。
如果此對(duì)象被破壞,則不應(yīng)使用它;調(diào)用除isDestroyed
以外的任何函數(shù)都將導(dǎo)致DeveloperError
異常。