OPENGL - 从纹理颜色更改顶点位置

OPEN GL - Change Vertex position from a texture color

我有一个平面,由 NURB 曲面制成,具有许多顶点,因此它可以根据顶点位置(控制点)创建曲面。

我给平面对象绑定了两种不同的贴图,一种是要显示在对象上的彩色贴图,另一种是heightMap,(黑白),需要改变顶点yy平面的位置取决于相应纹理坐标中的白色。

我知道问题出在我的着色器上。我对 OPENGL 的经验不多。

这是我使用的shader.vert

attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec2 aTextureCoord;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat4 uNMatrix;

varying vec2 vTextureCoord;

uniform sampler2D uSampler2;

uniform float heightScale;

void main() {

//change texture coordinates
vec2 texInver=vec2(1.0, -1.0);

vTextureCoord = aTextureCoord*texInver;
//--------------------------

//change vertex position
vec4 filter = texture2D(uSampler2, vTextureCoord);

float offset = filter.r;

vec3 inc = vec3(0.0, offset, 0.0);

gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition + inc, 1.0);
//----------------------
}

由于图像是黑白的,R = G = B。这就是为什么我只检查 filter.r

而我的 shader.frag 是:

#ifdef GL_ES
precision highp float;
#endif

varying vec2 vTextureCoord;

uniform sampler2D uSampler;

void main() {
gl_FragColor = texture2D(uSampler, vTextureCoord);
}

这是高度图(.jpg):

我得到的结果是一个平面在yy坐标中全部增加1。

我期望的结果是平面的某个顶点在 yy 坐标中增加 0-1 值。

I was forgetting to change the number of the object's vertexes

原来是这个问题,我做了之后就解决了