Jump to content
  • Advertisement
Sign in to follow this  
Tachikoma

Glsl Vertex Displacement Mapping

This topic is 2895 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'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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.[/quote]
I'm not sure either, I'll investigate.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!