Okay, I'll do a search for the topic. I'll mess around with the properties and scaling some more as well.
I'm so close though, here's a picture illustrating the problem.
[img src="http://www.curvedbasic.com/normalproblem.JPG"]
:)
2D normal map generation
Okay, to generate my height map, I'm just trying to enhance/exaggerate each color after it's been made into a greyscale. So any color greater than 128 rgb will become whiter, while colors less than that will become darker. This will be perfect for objects that aren't complex, but I may end up having users to just draw over dark areas, or have some kind of replace color function.
I'm still open to all links on 2D normal map generation and height map alogrithms.
Thanks.
I'm still open to all links on 2D normal map generation and height map alogrithms.
Thanks.
Here is a thread about generationg normals from heightmap that explains the use of sobel operator. This is the same way nVidia plugin works.
And here is a sample code using it:
And here is a sample code using it:
// converts heightmap to normalmap (bumpmap)void CImageTools::ConvertHeightMapToNormalMap( CImage &heightMap, CImage &normalMap, const float strength ) { // error checking if ( heightMap.GetDepth() != 1 ) { Log << "<!> Cant convert heightmap to normalmap : invalid input image depth\n"; return; } const unsigned int width = heightMap.GetWidth(); const unsigned int height = heightMap.GetHeight(); normalMap.Set( width, height, 3 ); const float normY = 256.0f / strength; Math::CVector3 normal; unsigned int pos = 0; for ( unsigned int y=0; y<height; ++y ) { for ( unsigned int x=0; x<width; ++x ) { normal.Set( 0.0f, normY, 0.0f ); normal.x -= static_cast<float>( heightMap.data[ heightMap.GetDataPos( x-1, y ) ] ); normal.x += static_cast<float>( heightMap.data[ heightMap.GetDataPos( x+1, y ) ] ); normal.z -= static_cast<float>( heightMap.data[ heightMap.GetDataPos( x, y-1 ) ] ); normal.z += static_cast<float>( heightMap.data[ heightMap.GetDataPos( x, y+1 ) ] ); normal.NormalizeFast(); normalMap.data[ pos++ ] = Math::FloatToByte( normal.x * 127.0f + 128.0f ); normalMap.data[ pos++ ] = Math::FloatToByte( normal.z * 127.0f + 128.0f ); normalMap.data[ pos++ ] = Math::FloatToByte( normal.y * 127.0f + 128.0f ); } } normalMap.SetDataFormat( GL_RGB, GL_RGB );}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement