Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Noisy Pictures

Sign in to follow this  


Well now that I can draw a pretty terrain I thought I should see about looking into how those rendering programs get those nice landscapes generated and lovely textures.

Whilst trying to get a marbly texture I managed to get the following image to appear using the following code:

bool DXTerrain::GenerateTexture(void)
int TexWidth = m_VertsPerRow;
int TexDepth = m_VertsPerCol;

SurfaceDescription sfcd = m_texture->GetLevelDescription(0);
if ( sfcd.Format != Format::X8R8G8B8 ) return false;
int* ImageData = (int*)m_texture->LockRectangle(0,LockFlags::None)->InternalData.ToPointer();
int m_rangeHeight = (int)(m_maxHeight / 5.0f);
Int32 m_Ranges __gc[] = new Int32[5];
for (int i=0; i < 5; i++)
m_Ranges = m_minHeight + (m_rangeHeight * i);
Random* r = new Random();
int rndR = r->Next(0,1000);
float t;
int f;
for (int i = 0; i < TexDepth; i++)
for (int j = 0; j < TexWidth; j++)
int c;
int index = (j * m_VertsPerCol + i);
float height = (m_heights[index]);

// Currugated Iron
t = (float)Math::Cos(i + m_noise->Perlin3D(j+rndR * 0.625f, i+rndR *0.625f, height+rndR * 0.625f));

// Weird Lattice Effect
//t = (float)Math::Cos(i + m_noise->Perlin3D(j+rndR * 0.625f, i+rndR *0.625f, height+rndR * 0.625f));

if(t<0) t = -t;
if(t>1) t = 1.0f;
int f = (int)(t * 255.0f);
c = Color::FromArgb(f,f,f).ToArgb();
ImageData[index] = c;
//m_texture->AutoGenerateFilterType = TextureFilter::Anisotropic;
return true;

The output looks like this:

Sign in to follow this  


Recommended Comments

There are no comments to display.

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
  • 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!