Sign in to follow this  

Texture problem

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

Hi I am having some trouble with a texture that I am creating
int size = 512;

// handle libnoise initialization
perlinNoiseMapBuilder.EnableSeamless( true );
perlinNoiseMapBuilder.SetSourceModule( perlinModule );
perlinNoiseMapBuilder.SetDestNoiseMap( perlinNoiseMap );
perlinNoiseMapBuilder.SetDestSize( size, size );
perlinNoiseMapBuilder.SetBounds( 2.0, 6.0, 1.0, 5.0 );
perlinNoiseMapBuilder.Build();

perlinRenderImage.SetSourceNoiseMap( perlinNoiseMap );
perlinRenderImage.SetDestImage( perlinImage );
perlinRenderImage.Render();
	
// create texture to use as surface normal map
DXRESULT( D3DXCreateTexture( device, size, size, 0, D3DUSAGE_DYNAMIC, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &mSurfaceNoiseMap ) );

// get surface memory from texture
Surface pSurface;
mSurfaceNoiseMap->GetSurfaceLevel( 0, &pSurface );

// lock memory for writing
D3DLOCKED_RECT rect = { 0 };
pSurface->LockRect( &rect, NULL, NULL );

// get start of memory
DWORD* imageData = ( DWORD* ) rect.pBits;

// write random noise to the surface
for ( UINT i = 0; i < pSurface->Height; ++i )
{
	for ( UINT j = 0; j < pSurface->Width; ++j )
	{
		int index = i * rect.Pitch / 4 + j;

		noise::utils::Color col = perlinImage.GetValue( i, j );
		imageData[ index ] = D3DCOLOR_XRGB( col.red, col.green, col.blue );
	}
}

// unlock memory
pSurface->UnlockRect();

// write surface to file 
D3DXSaveSurfaceToFile( "Surface.bmp", D3DXIFF_BMP, pSurface, NULL, NULL );

// release memory
RELEASE( pSurface );



Now this is what Surface.bmp looks like: So the surface contains Perlin noise, but when rendered with a simple pixel shader that looks up the color based on position, this is how it looks like: So obviously something goes wrong some where with the texture. What can it be?

Share this post


Link to post
Share on other sites
The bitmap image you posted (which is beautiful, by the way) serves as strong evidence that your Perlin noise algorithm and bitmap exporter are working just fine.

Judging from the results, the texture's lower mip-levels aren't being initialised. When you manually create a texture and fill in its base surface level (as you are), you need to tell Direct3D to create the mip-maps manually, once you're done. A single call to IDirect3DBaseTexture9::GenerateMipSubLevels at the end of the function would be a step in the right direction.

Admiral

Share this post


Link to post
Share on other sites
Hey thanks for the answer. I just came to the same conclusion after plowing through the docs [smile]. After specifying D3DUSAGE_AUTOGENMIPMAP at creation of the texture and calling GenerateMipSubLevels() afterwards it works out.

Share this post


Link to post
Share on other sites

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

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