• Advertisement
Sign in to follow this  

Heightmap - Vertex Shader

This topic is 3266 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to use a heightmap within a vertex shader to set the z-value of the incoming vertex, but I've got some trouble with this. It works for me fine, if I write: uniform sampler2D heightMap; uniform vec2 dimension; const float height = 10.0; void main() { vec4 vertex = vec4(gl_Vertex); vec2 texCoord = vec2(vertex.x/dimension.y, vertex.y/dimension.x); float offset = height * texture2D(heightMap, texCoord).r; if (texCoord.x <= 1.0 && texCoord.x >= 0.0 && texCoord.y <= 1.0 && texCoord.y >= 0.0) { vertex.z += offset; } gl_FrontColor = gl_Color; gl_Position = gl_ModelViewProjectionMatrix * vertex; } BUT if I eliminate the if, it doesn't work anymore: uniform sampler2D heightMap; uniform vec2 dimension; const float height = 10.0; void main() { vec4 vertex = vec4(gl_Vertex); vec2 texCoord = vec2(vertex.x/dimension.y, vertex.y/dimension.x); float offset = height * texture2D(heightMap, texCoord).r; vertex.z += offset; gl_FrontColor = gl_Color; gl_Position = gl_ModelViewProjectionMatrix * vertex; } I'm confuesed. Does anybody know why the second doesn't work?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by enkei
Does anybody know why the second doesn't work?
Define 'doesn't work'? Does your terrain come out flat, or does it not display at all, or something else entirely? Screenshots are often helpful as well.

Share this post


Link to post
Share on other sites
Doesn't work=I can't see anything. Everything is black (glClearColor(0.0,0.0,0.0,1.0))

Share this post


Link to post
Share on other sites
Are you getting any errors? What hardware are you on? Are you running the latest drivers?

Share this post


Link to post
Share on other sites
I'm sure the problem is your texture. Check to see if the texture shows correctly on screen.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement