Glsl Vertex Displacement Mapping

Started by
2 comments, last by Tachikoma 13 years, 3 months ago
I'm having some problems using a texture for applying displacement mapping on my vertices. Basically I have a VBO consisting of a grid. The aim is to displace the vertex by whatever the texel luminance value is for that vertex.

Admittedly, I'm still new to GLSL, perhaps I've missed something fundamental. Sample vertex shader is provided below:

uniform sampler2D Texture;

vec3 LumConst = vec3(0.2990, 0.5870, 0.1140);

varying float Z;

void main(void)
{
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

vec4 Texel = texture2DLod(Texture, gl_TexCoord[0].st, 0.0);
Z = dot(Texel.rgb, LumConst);

gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xy, gl_Vertex.z + Z, gl_Vertex.w);
}


What's happening there is that I'm grabbing the RGB value for each texel at the vertices, apply RGB-to-luminance transform and use the result to displace the Z component of the vertex position.

The only problem is, the program does not seem to fetch the texel. The computed Z value is always 0. The texel coordianes are correct at each vertex, I checked (I've fed either the .s or .t component to Z value for testing). The texture also seems to be bound correctly, because i can render it in the fragment shader using the same uniform name. The actual texture itself is uploaded as a 16-bit height map, I'm not sure if that would be a problem though.

My hardware is an 8600 GT with GL 2.1 capable drivers.
Latest project: Sideways Racing on the iPad
Advertisement
Does GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB return a sensible value?

Not sure where the GeForce 8 fits in, but older cards did require vertex-textures to be in a 32-bit floating-point format.

Does GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB return a sensible value?

I'm getting 32, so plenty to spare

Not sure where the GeForce 8 fits in, but older cards did require vertex-textures to be in a 32-bit floating-point format.
I'm not sure either, I'll investigate.
Latest project: Sideways Racing on the iPad
Update: Well... I'm an idiot, aren't I? The texture was unbound after all!

Cheers for the tip anyway.
Latest project: Sideways Racing on the iPad

This topic is closed to new replies.

Advertisement