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:
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:
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.
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;
}