increasing heightmap resolution

Started by
6 comments, last by vNistelrooy 17 years, 10 months ago
ive got a heightmap with the size "res" (ex res =256 = 256x256 field) and i want to increase the resolution of this field to match the size "res2"... i want to use the values from the "original" field and calculate the values between the different points based on their distance from the other points... ex... res = 2: P P P P res = 3: P P P P P P P P P then the values to be calculated based on the 4 know points are... (K are points with known values and X are poitns with unknown values): K X K X X X K X K i need a function which can acomplish this with different values of res and res1 the field used in the function should be HeightMap[res][res] and the resulting field should be EHeightMap[res1][res1] hope u understood... ive been trying to figure this out for a few days without luck... i know the basic idea but i cant seem to implement it into code... any help will be appriciated...
Advertisement
If you have 4 points in an axis-aligned regular grid whose heights are h00, h01, h10, and h11 like this:
    (0,1,h01)  (1,1,h11)         +--------+        |        |        |        |        |    X<----- (x,y,z)        |        |        +--------+    (0,0,h00)  (1,0,h10) 
Then, here is one way of calculating the height of a point in the middle:
    z = (1-x)(1-y)h00 + x(1-y)h10 + (1-x)yh01 + xyh11 
Of course, you need to account for the offset of each quad and the scale, too.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
yes i know that part... but what im having problems with is writing a code for it...
It seems like it should be pretty straightforward. What kind of problems are you having?
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
im having problems for the code looping through the mesh... just made a test for the looping... here the original heightmap would be 256 and the new 512... which makes each quad 2 points wide... so i make the loop jump two points each time after calculating the nerby unkown points.. which in my mind should give the following results

quad 1: -> quad 2:
XX -> XX
KX -> KX

so i should get if i have W (white) for known points and B (black) for unknown points.. i should get a pattern like this..

B B B B
W B W B
B B B B
W B W B

this is the code...

for( int z1=0; z1<512; z1+=2 )
{
for( int x1=0; x1<512; x1+=2)
{
ESlopeMap[x1][z1] = 1.0f;
ESlopeMap[x1+1][z1] = 0.0f;
ESlopeMap[x1][z1+1] = 0.0f;
ESlopeMap[x1+1][z1+1] = 0.0f;
}

}


and this what i get...

http://www.imagehosting.us/index.php?action=show&ident=1397809

looks good on some parts.. but i get white and black lines where i get 2 black and 2 white points after eachother... which shouldnt be there...

i know this is a rly noobish problem... but i cant seem to figure it out today... sigh..
Quote:Original post by JohnBolton
If you have 4 points in an axis-aligned regular grid whose heights are h00, h01, h10, and h11 like this:
    (0,1,h01)  (1,1,h11)         +--------+        |        |        |        |        |    X<----- (x,y,z)        |        |        +--------+    (0,0,h00)  (1,0,h10) 
Then, here is one way of calculating the height of a point in the middle:
    z = (1-x)(1-y)h00 + x(1-y)h10 + (1-x)yh01 + xyh11 
Of course, you need to account for the offset of each quad and the scale, too.


Bilinear interpolation isn't useful for increasing the resolution of a height map, as, practically, no detail is added. Bicubic interpolation is more suitable.
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
i was thinking more about cosine interpolation... give similar detail but faster
Quote:Original post by Dragon_Strike
i was thinking more about cosine interpolation... give similar detail but faster


No it doesn't. Bicubic interpolation takes into account neighboring texels, which means your heightmap's slopes will look more natural, but if cosine interpolation works for you...
Anyway why are you doing all this dirty work? Just resize the heightmap.

// This was quickly hacked together so it might actually cause your // computer to explode, make hell freeze over, etc.// Use at your own risk.const int oldres=256;const int newres=512;const float r=(float)oldres/(float)newres;for(int z1=0; z1<newres; z1++){ for(int x1=0; x1<newres; x1++) {  int x0=(int)((float)x1*r);  int z0=(int)((float)z1*r);  float d0=(float)x1*r - (float)x0;  float d1=(float)z1*r - (float)z0;  float l0=(1-cos(d0*PI))/2;  float l1=(1-cos(d1*PI))/2;  float a0=OldMap[x0][z0]*(1-l0) + OldMap[(x0+1)&(oldres-1)][z0]*l0;  float a1=OldMap[x0][(z0+1)&(oldres-1)]*(1-l0) + OldMap[(x0+1)&(oldres-1)][(z0+1)&(oldres-1)]*l0;  NewMap[x1][z1]=a0*(1-l1) + a1*l1; }}
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

This topic is closed to new replies.

Advertisement