• Advertisement
Sign in to follow this  

Sampling at the Edges of Heightmaps for Normal Mapping

This topic is 1324 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

Hello, 

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?

Thanks. 

Share this post


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

  • Advertisement