location not for current program

1. A concise explanation of the problem you're experiencing.

Console warning: location not for current program

2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.

copyCurrFBO(){
        let _this = this;
        let context = this.viewer.scene.context;
        if(!this._copyDepthCommand){
            var fs =
            'uniform sampler2D u_texture;\n' +
            'varying vec2 v_textureCoordinates;\n' +
            'void main()\n' +
            '{\n' +
            ' gl_FragColor = czm_packDepth(texture2D(u_texture, v_textureCoordinates).r);\n' +
            '}\n';
            this._copyDepthCommand = context.createViewportQuadCommand(fs, {
                renderState : Cesium.RenderState.fromCache(),
                uniformMap : {
                    u_texture : function() {
                        return _this.mergeFBO._colorTextures[0];
                    }
                },
                framebuffer:_this.copyCommandFBO
            });
            this.clearCopy = new Cesium.ClearCommand({
                color: new Cesium.Color(0.0, 1.0, 0.0, 0.0),
                framebuffer: _this.copyCommandFBO
            });
        }
        this.clearCopy.execute(context);
        this._copyDepthCommand.execute(context);
        return this.copyCommandFBO._colorTextures[0];
    }

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

I want to copy a text standby in the frame buffer, and then report this error. I don't know where the uniform variable is wrong. The error table variables are uniformMatrix 4fv, uniform1f, uniform3f, uniform4f

4. The Cesium version you're using, your operating system and browser.
1.59

It’s hard to tell what the issue is just from looking at this code snippet. If you have a full Sandcastle code example (https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html) I can run that’d help.

What kind of feature are you trying to implement here?

It’s hard to tell what the issue is just from looking at this code snippet. If you have a full Sandcastle code example (https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html) I can run that’d help.

What kind of feature are you trying to implement here?

  1. A concise explanation of the problem you’re experiencing.
    Console warning: location not for current program
  1. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

copyCurrFBO(){
let _this = this;
let context = this.viewer.scene.context;
if(!this._copyDepthCommand){
var fs =
‘uniform sampler2D u_texture;\n’ +
‘varying vec2 v_textureCoordinates;\n’ +
‘void main()\n’ +
‘{\n’ +
’ gl_FragColor = czm_packDepth(texture2D(u_texture, v_textureCoordinates).r);\n’ +
‘}\n’;
this._copyDepthCommand = context.createViewportQuadCommand(fs, {
renderState : Cesium.RenderState.fromCache(),
uniformMap : {
u_texture : function() {
return _this.mergeFBO._colorTextures[0];
}
},
framebuffer:_this.copyCommandFBO
});
this.clearCopy = new Cesium.ClearCommand({
color: new Cesium.Color(0.0, 1.0, 0.0, 0.0),
framebuffer: _this.copyCommandFBO
});
}
this.clearCopy.execute(context);
this._copyDepthCommand.execute(context);
return this.copyCommandFBO._colorTextures[0];
}

  1. Context. Why do you need to do this? We might know a better way to accomplish your goal.

I want to copy a text standby in the frame buffer, and then report this error. I don’t know where the uniform variable is wrong. The error table variables are uniformMatrix 4fv, uniform1f, uniform3f, uniform4f

  1. The Cesium version you’re using, your operating system and browser.
    1.59

Hey, I have tried it the way he did, or not. I just found a problem. The depthTexture of postStage is viewer.scene._view.globeDepth.framebuffer.depthStencilTexture, but this depth map is used in my shader.
Float getDepth(in vec4 depth){
Float z_window = czm_unpackDepth(depth);
Z_window = czm_reverseLogDepth(z_window);
Float n_range = czm_depthRange.near;
Float f_range = czm_depthRange.far;
Return (2.0 * z_window - n_range - f_range) / (f_range - n_range);
}
Vec4 currD = texture2D(depthTexture, v_textureCoordinates);
Float depth = getDepth(currD);

The result of depth is between -1-0, the result of postStage is not like this, this is why, how can I resolve the depth map?

在 2019年7月17日星期三 UTC+8上午3:09:38,Omar Shehata写道:

Hi:

I have been troubled by this problem for a long time, I really hope that you can help me, why the same depth texture, the same fragment shader code, the depth of the parsing is not the same, I think it is the same depth texture, because I assigned the depth map to the front of PostProcessStage in the source code and passed it to my custom command. The depth of the PostProcessStage parsing is correct. The result of my custom command parsing is between -1-0. Why is this?

在 2019年7月17日星期三 UTC+8上午3:09:38,Omar Shehata写道:

If you can provide a complete Sandcastle example (https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html) that I can run that shows the issue, I’d be happy to take a look.

I am very sorry, I will reply you so late. I made a simple example. By changing the source code, before the depth map is used in postStage, my code is used first. The depth of the result is negative. You can run my example to see it.
I don’t know why I can’t send attachments, I can only paste the code in the reply, I am sorry to give you trouble.

Here is where I am modifying the source code.It’s in the Scene.js file, the testDepthTexture method is what I added.

if (usePostProcess) {

var inputFramebuffer = sceneFramebuffer;

if (useGlobeDepthFramebuffer && !useOIT) {

inputFramebuffer = globeFramebuffer;

}

var postProcess = scene.postProcessStages;

var colorTexture = inputFramebuffer.getColorTexture(0);

var idTexture = idFramebuffer.getColorTexture(0);

var depthTexture = defaultValue(globeFramebuffer, sceneFramebuffer).depthStencilTexture;

if(Cesium.testDepthTexture){

Cesium.testDepthTexture.execute(context, colorTexture, depthTexture, idTexture);

}

postProcess.execute(context, colorTexture, depthTexture, idTexture);

postProcess.copy(context, defaultFramebuffer);

}

var fragmentShader = `

uniform sampler2D colorTexture;

uniform sampler2D depthTexture;

varying vec2 v_textureCoordinates;

vec4 toEye(in vec2 uv, in float depth){

vec2 xy = vec2((uv.x * 2.0 - 1.0),(uv.y * 2.0 - 1.0));

vec4 posInCamera =czm_inverseProjection * vec4(xy, depth, 1.0);

posInCamera =posInCamera / posInCamera.w;

return posInCamera;

}

float getDepth(in vec4 depth){

float z_window = czm_unpackDepth(depth);

z_window = czm_reverseLogDepth(z_window);

float n_range = czm_depthRange.near;

float f_range = czm_depthRange.far;

return (2.0 * z_window - n_range - f_range) / (f_range - n_range);

}

void main()

{

vec4 currD = texture2D(depthTexture, v_textureCoordinates);

if(currD.r>=1.0){

gl_FragColor = texture2D(colorTexture, v_textureCoordinates);

return;

}

float depth = getDepth(currD);

gl_FragColor = vec4(depth,0.0,0.0,1.0);

}`;

function testDepthTexture(viewer){

this.viewer = viewer;

this.init();

}

testDepthTexture.prototype.init = function(){

var _this = this;

this.viewer.scene.logarithmicDepthBuffer = true;

this.viewer.scene.globe.depthTestAgainstTerrain = true;

this.createFBO();

this.viewer.scene._postRender.addEventListener(function(){

_this.clearFBOCD.execute(_this.viewer.scene.context);

});

this.addPostProcess();

}

testDepthTexture.prototype.execute = function(context, colorTexture, depthTexture, idTexture){

this._defaultColorTexture = colorTexture;

this._defaultDepth = depthTexture;

this.showDepth();

}

testDepthTexture.prototype.createFBO = function(){

let context = this.viewer.scene.context;

let size = this.getWinSize();

let width = size.width;

let height = size.height;

this.mergeFBO = this.createMergeFBO(context,width,height);

this.clearFBOCD = this.cretaeClearFBOCD(this.mergeFBO);

}

testDepthTexture.prototype.createMergeFBO = function(context,width,height){

let tt = new Cesium.Texture({

context: context,

width: width,

height: height

});

return new Cesium.Framebuffer({

context: context,

colorTextures: [tt]

});

}

testDepthTexture.prototype.cretaeClearFBOCD = function(fbo){

if(!fbo)return;

var cc = new Cesium.ClearCommand({

color: new Cesium.Color(0.0, 0.0, 0.0, 0.0),

framebuffer: fbo

});

cc.pass = Cesium.Pass.OVERLAY;

return cc;

}

testDepthTexture.prototype.getWinSize = function(){

return {

width:this.viewer.scene.drawingBufferWidth,

height:this.viewer.scene.drawingBufferHeight

}

}

testDepthTexture.prototype.showDepth = function(){

var _this = this;

var context = this.viewer.scene.context;

if(!this.drawDepthCommand){

var uniformMap = {

colorTexture:function(){

return _this._defaultColorTexture

},

depthTexture:function(){

return _this._defaultDepth

}

}

var fbo = this.mergeFBO;

var rs = new Cesium.RenderState();

rs.depthTest.enabled = false;

var pass = Cesium.Pass.OVERLAY;

this.drawDepthCommand = context.createViewportQuadCommand(fragmentShader,{

renderState:rs,

uniformMap:uniformMap,

framebuffer:fbo,

pass:pass

});

}

this.drawDepthCommand.execute(this.viewer.scene.context);;

}

testDepthTexture.prototype.addPostProcess = function(){

var _this = this;

var fs =

“uniform sampler2D colorTexture;”+

“uniform sampler2D depthTexture;”+

“varying vec2 v_textureCoordinates;”+

“vec4 toEye(in vec2 uv, in float depth){”+

“vec2 xy = vec2((uv.x * 2.0 - 1.0),(uv.y * 2.0 - 1.0));”+

“vec4 posInCamera =czm_inverseProjection * vec4(xy, depth, 1.0);”+

“posInCamera =posInCamera / posInCamera.w;”+

“return posInCamera;”+

“}”+

“float getDepth(in vec4 depth){”+

“float z_window = czm_unpackDepth(depth);”+

“z_window = czm_reverseLogDepth(z_window);”+

“float n_range = czm_depthRange.near;”+

“float f_range = czm_depthRange.far;”+

“return (2.0 * z_window - n_range - f_range) / (f_range - n_range);”+

“}”+

"void main() "+

“{”+

“vec4 currD = texture2D(depthTexture, v_textureCoordinates);”+

“vec4 oldc = texture2D(colorTexture, v_textureCoordinates);”+

“if(currD.r>=1.0){”+

" gl_FragColor = texture2D(colorTexture, v_textureCoordinates);"+

“return;”+

“}”+

“float depth = getDepth(currD);”+

// “gl_FragColor = currD;”+

“gl_FragColor = oldc;”+

“}”;

this.depthProcess = new Cesium.PostProcessStage({

fragmentShader: fs,

uniforms: {

colorTexture: function () {

return _this.mergeFBO._colorTextures[0];

}

}

});

this.viewer.scene.postProcessStages.add(this.depthProcess);

}

I think the easiest way to share running code examples is with Sandcastle (https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html). You can put together your example here, then click “Share” and paste the link here.

If it’s a modified version of the source code, you could post a link to your fork of CesiumJS on GitHub, and I could still run the Sandcastle with your fork.

https://github.com/herewaitting/Cesium-question

Sorry, I didn’t think of using github yesterday.Above is my warehouse address.