tilezen / joerd

Joerd can be used to download, merge and generate tiles from digital elevation data
MIT License
324 stars 50 forks source link

Support 16-bit PNGs (with 2-channels) #30

Closed nvkelso closed 8 years ago

nvkelso commented 8 years ago

Team Tangram has requested raw 16-bit elevations, as a 2-channel PNG (two channels of 8 bits each).

/cc @bcamper @blair1618

bcamper commented 8 years ago

@zerebubuth and @blair1618 should confirm that this is what we discussed to make sure I remembered properly :) (And same for normals maps, assume in different issue)

zerebubuth commented 8 years ago

I've updated the title of this, as I was confused: When I read "16-bit PNG" the first thing I think of is 16-bit channels, but that wasn't what was meant.

Additionally: We discussed using 2 channels for the moment, but leaving the 3rd as a fractional channel for future use. It turns out that NED has fractional heights, so we can start using that now. I propose that we do the following:

uheight = height + 16384.0
[r, g, b] = [int(uheight) >> 8, int(uheight) & 255, int(frac(uheight) * 256]

Does that sound like it'll work well enough, shader-side?

bcamper commented 8 years ago

Yes, sounds good. So it's 24-bits of precision, in a fixed-point 16.8 format (16 bits of integer, 8 bits of fraction).

matteblair commented 8 years ago

Yeah, makes sense to me!

float height = (texel.r * 256.0 + texel.g + texel.b / 256.0) - 16384.0;
zerebubuth commented 8 years ago

Oops, that should have been:

uheight = height + 32768

Although I'm not sure it would have mattered; Challenger Deep is only 10,916m, so we've got a bit to spare :wink: