# 回复：\[cesium-dev\] Re: how transport a picture to postProcessStage

**URL:** https://community.cesium.com/t/cesium-dev-re-how-transport-a-picture-to-postprocessstage/7803
**Category:** CesiumJS
**Created:** [December 14, 2018, 4:27pm UTC](https://community.cesium.com/t/cesium-dev-re-how-transport-a-picture-to-postprocessstage/7803 "2018-12-14T16:27:08Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![noble](https://avatars.discourse-cdn.com/v4/letter/n/e19b73/32.png) [@noble](https://community.cesium.com/u/noble)
#### Post date: [December 14, 2018, 4:27pm UTC](https://community.cesium.com/t/cesium-dev-re-how-transport-a-picture-to-postprocessstage/7803/1 "2018-12-14T16:27:08Z")

</div>

do i need bind texture created by webgl to a textureUint? what’ the max number of textureUnit used by cesium?

---

<div class="post-metadata">

### Author: ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)
#### Post date: [December 17, 2018, 6:25pm UTC](https://community.cesium.com/t/cesium-dev-re-how-transport-a-picture-to-postprocessstage/7803/2 "2018-12-17T18:25:28Z")

</div>

It’s hard to tell here without seeing your full code. Have you already successfully rendered the scene to a texture? Can you show the code for that?

> By the way ,are gl\_FragCoord.z and gl\_FragCoord.w in postProcessStage the same as raw WebGL ?

It should be, yes.

---

<div class="post-metadata">

### Author: ![noble](https://avatars.discourse-cdn.com/v4/letter/n/e19b73/32.png) [@noble](https://community.cesium.com/u/noble)
#### Post date: [December 18, 2018, 4:06pm UTC](https://community.cesium.com/t/cesium-dev-re-how-transport-a-picture-to-postprocessstage/7803/3 "2018-12-18T16:06:05Z")

</div>

a lot of errors from consolo,like below

WebGL: INVALID\_ENUM: bindTexture: invalid target

[.WebGL-11FFF320]RENDER WARNING: there is no texture bound to the unit 0

and it seems render to srceen when I use ”viewer.scene.render()“ after “gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)”

these are my code ,but it seems not work properly.

//store current camera status

var curCameraPos = viewer.scene.camera.positionWC;

var curCameraDir = viewer.scene.camera.direction;

var curCameraUp = viewer.scene.camera.up;

//camera go to light postion

viewer.scene.camera.position = visibleStartPoint;

viewer.scene.camera.direction = new Cesium.Cartesian3(endPoint.x - visibleStartPoint.x, endPoint.y - visibleStartPoint.y, endPoint.z - visibleStartPoint.z)

//record lightView Matrix;

var lightViewMatrix = viewer.scene.camera.viewMatrix;

// Get the rendering context for WebGL

var gl = viewer.canvas.getContext(“webgl”)

> > viewer.canvas.getContext(“experimental-webgl”);

var OFFSCREEN\_WIDTH = 2048, OFFSCREEN\_HEIGHT = 2048;

gl.activeTexture(gl.TEXTURE0);

//create frameBufferObject

var fbo = initFramebufferObject(gl, OFFSCREEN\_WIDTH,OFFSCREEN\_HEIGHT);

gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); // Change the drawing destination to FBO

gl.viewport(0, 0, OFFSCREEN\_HEIGHT, OFFSCREEN\_HEIGHT); // Set view port for FBO

gl.clear(gl.COLOR\_BUFFER\_BIT | gl.DEPTH\_BUFFER\_BIT); // Clear FBO

//render to fbo

viewer.scene.render();

// Change the drawing destination to color buffer

gl.bindFramebuffer(gl.FRAMEBUFFER, null);

gl.viewport(0, 0, viewer.canvas.width, viewer.canvas.height);

gl.clear(gl.COLOR\_BUFFER\_BIT | gl.DEPTH\_BUFFER\_BIT); // Clear

//restore camera postion

viewer.scene.camera.position = curCameraPos;

viewer.scene.camera.direction = curCameraDir;

viewer.scene.render();//

//then I add texture of fbo to postProcessStage

viewer.scene.postProcessStages.add(new Cesium.PostProcessStage({

fragmentShader: FSHADER\_SOURCE,

uniforms: {

u\_ShadowMap: fbo.texture}

});

---

<div class="post-metadata">

### Author: ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)
#### Post date: [December 18, 2018, 9:58pm UTC](https://community.cesium.com/t/cesium-dev-re-how-transport-a-picture-to-postprocessstage/7803/4 "2018-12-18T21:58:32Z")

</div>

I think you might need to dig around in the source to see some examples of this. I think you need to initialize a Texture object:

[https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Renderer/Texture.js](https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Renderer/Texture.js)

Or possible just use the createUniform function to wrap it:

[https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Renderer/createUniform.js](https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Renderer/createUniform.js)

You might also find this series helpful for context in understanding Cesium’s rendering engine and where to look in the source code:

> **[Graphics Tech in Cesium - Renderer Architecture | cesium.com](https://cesium.com/blog/2015/05/15/graphics-tech-in-cesium-architecture/)**
>
> Cesium is built on a custom WebGL engine - the Renderer - that we started developing in March 2011 when the WebGL 1.0 spec was released. I consider this a 4...

And more blogs on that:

[https://cesium.com/blog/categories/webgl/](https://cesium.com/blog/categories/webgl/)

---

<div class="post-metadata">

### Author: ![noble](https://avatars.discourse-cdn.com/v4/letter/n/e19b73/32.png) [@noble](https://community.cesium.com/u/noble)
#### Post date: [June 14, 2019, 6:24am UTC](https://community.cesium.com/t/cesium-dev-re-how-transport-a-picture-to-postprocessstage/7803/5 "2019-06-14T06:24:51Z")

</div>

## Is there some example code for rendering to FBO, I am still blocked here

---

<div class="post-metadata">

### Author: ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)
#### Post date: [June 20, 2019, 9:49pm UTC](https://community.cesium.com/t/cesium-dev-re-how-transport-a-picture-to-postprocessstage/7803/6 "2019-06-20T21:49:00Z")

</div>

I think Rayman’s blog post here talks a bit about it, and there’s a link to his app’s source code that might be helpful:

[https://cesium.com/blog/2019/04/29/gpu-powered-wind/](https://cesium.com/blog/2019/04/29/gpu-powered-wind/)
