Sign in to follow this  

Sampling at the Edges of Heightmaps for Normal Mapping

Recommended Posts


I am creating heightmaps on the GPU and then using a Sobel filter to create a normal map for that heightmap. The Sobel filter works by sampling the 8 pixels surrounding a central pixel. The obvious problem is that when the central pixel is located on the edge of a heightmap the filter will not be able to sample all the edges. To resolve this problem I decided to expand the size of the heightmap from 256x256 pixels to 258x258 pixels. Then when I generate the heightmap for a particular quad I do the following: 

vec3 p = vec3(uv.x, 0.0, uv.y);

//size is the size of the current quad
p *= (size + 2);
p -= (1.0/(size + 2.0));
//'meshoffset' offsets the scaled meshes points from the origin
p += meshOffset;

when it comes to sample the heightmap I warp the UV coordinates like so: 

//the uv coordinates range from (0.0,0.0),(0.0, 1.0/17.0),(0.0, 2.0/17.0)...-> (1.0, 1.0)
uv *= (15.0/17.0);
uv += (1.0/17.0);

yet this still does not cause the edges to match up. 


Does anyone have any experience with this?


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this