Trying to use an FBO to texture a plane and a shader to give it depth

Hi all,
I am using a shader to draw a noise field (kind of) and have captured that to an FBO. It works great to make a plane and bind a texture to that plane like so:

warpFBO.getTextureReference().bind();
warpPlane.draw();
warpFBO.getTextureReference().unbind();

however I want to use a shader so I can take the vertices of the plane and set them higher or lower in Z depth based on the color of that pixel (I know I can do it on the cpu but I want to save some juice here).

It doesn’t seem to work. In fact, I can’t even get it to just draw the texture at all on the plane if I try:

warpPlaneShader.begin();
warpFBO.getTextureReference().bind();
warpPlane.draw();
warpFBO.getTextureReference().unbind();
warpPlaneShader.end();

with warpPlane.vert:

#version 120

//just a simple pass through vertex shader
uniform sampler2D tex;
 
void main(){
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

and warpPlane.frag:

#version 120
//just a simple passthrough fragment shader
uniform sampler2D tex;

void main(){
    gl_FragColor = gl_Color;
}

doing this, i just get a black plane. What am I doing wrong?

Hi there!

You are trying to do a displacement, like so, I think you should first check the texture as data example here. It’s what you want to achieve. You may be uploading the texture, but you are not using it at all.

I had actually gone through those a couple of weeks ago, but your suggestion caught my attention.

The trick ended up being to bind before the shader began

fbo.getTextureReference().bind();
warpPlaneShader.begin();
warpPlane.draw();
warpPlaneShader.end();
fbp.getTextureReference().unbind();

and to modify the z in the vertex shader BEFORE multiplying it by the projection matrix and the modelView Matrix

#version 120
#extension GL_ARB_texture_rectangle : enable
uniform sampler2DRect tex0;

varying vec2 texCoordVarying;

void main()
{
	// get the texture coordinates for the fragment shader
	texCoordVarying = gl_MultiTexCoord0.xy;

	// get the position of the vertex relative to the modelViewProjectionMatrix
	vec4 position = gl_Vertex;  // ftransform();

	// we need to scale up the values we get from the texture
	float scale = 20;

	// here we get the red channel value from the texture
	// to use it as zdisplacement
	float displacementZ = texture2DRect(tex0, texCoordVarying).x; 
	position.z -= displacementZ * scale;
	
	//resultant position is only multiplied at the end
	gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix *position;
}

I get this great result of drawing a noise FBO: