Jump to content
  • Advertisement
Sign in to follow this  
keyofrassilon

Scaled Bitmap Buffer

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

Ok how to explain this... What I am trying to do is apply a heightmap that is scaled 1:256...(1 pixel = 256 units) and applying it to a mesh for terrain rendering. I already use perlin noise to give me a bit of variance. but sadly it isnt enough. The scaled heightmap will obviously produce mesas 256x256 units in my terrain even when I apply the perlin noise to the returned color variables of my heightmap. The abrupt edge between 2 colors needs to be smoothed somehow this much I know. Now how would I go about smoothing the pixel color variations? If I have pixel one as 255 and pixel 2 as 0 what about pixel 1.5? Obviosly 128 right...Now the problem I am having is coming up with a fast way of producing this. I could use a ton of assignments and if statements but that slows the render down to a crawl... So basically what I want to do is a sort of nearest neighbor color calculation with a resolution of 256 units between each pixel. So far I have this basic code that half-asses the process.
double Terrain::landHeight(double x, double y, SCALE_P s) {
	int red,green,blue;
	int where;
	double image_color;
	//double perlin = (PerlinNoise2D(x*s.s1,y*s.s2,s.s3,s.s4,1)+1)/2;
	int X = abs((int)x/256);
	int Y = abs((int)y/256);

	double iX = (absd(x)/256) - X;
	double iY = (absd(y)/256) - Y;
	
	//print(iX);

	if(X > 1024) X = 1024;
	if(Y > 512) Y = 512;
	if(X < 0) X = 0;
	if(Y < 0) Y = 0;

	where = (((int)X+0)*3) * (((int)Y+0)+1024); // center point

	red = planet_texRGB[planet[nearest_obj].landTexID].imageData[where];
	green = planet_texRGB[planet[nearest_obj].landTexID].imageData[where+1];
	blue = planet_texRGB[planet[nearest_obj].landTexID].imageData[where+2];
	image_color = ((double)(red + green + blue) * 0.3333) * iX;
	//if(where+2 > 1572864) where = 1572864-where;
	return image_color/256;
}

To turn this: ___ | | -- -- into this: /--/ \-- Any suggestions? Thanks! [Edited by - keyofrassilon on September 20, 2004 8:27:54 PM]

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!