PDA

View Full Version : Tessellation heightmap



glararan
09-05-2013, 09:35 AM
Hi,

I started this topic because I need help with choosing heightmap structure.

Currently I'm using:
Extension: .PNG
Resolution: 1024x1024
Bits: RGB 8-bit
Tessellation minimum, maximum height: 0-32

What I'm looking for?
Extension: ? (I suppose best is .raw?)
Resolution: 1024x1024
Bits: 32bit float? (I read somewhere its best way?)
Tesselation minimum, maximum height: float min, float max (Don't have to be float min, float max but it's terrible to work with maximum height 32, I suppose to work with -25000.0 to 25000.0 height)

Can you help me with choose? Then direct me how to implement this to glTexImage2D

Thanks for reply :)

glararan
09-06-2013, 09:59 AM
BUMP

I find on google some info about 32bit. 32bit float doesn't have limits for height. 16bit has about 0-65k.


I tried to recode loading from img to generate 0 height in float, but it crashing my driver:
Old code to load map:

SamplerPtr sampler(new Sampler);
sampler->create();
sampler->setMinificationFilter(GL_LINEAR);
sampler->setMagnificationFilter(GL_LINEAR);
sampler->setWrapMode(Sampler::DirectionS, GL_CLAMP_TO_EDGE);
sampler->setWrapMode(Sampler::DirectionT, GL_CLAMP_TO_EDGE);

heightMapImage.load("heightmap-1024x1024.png");

m_funcs->glActiveTexture(GL_TEXTURE0);

TexturePtr heightMap(new Texture);
heightMap->create();
heightMap->bind();
heightMap->setImage(heightMapImage);

New code to load map:

SamplerPtr sampler(new Sampler);
sampler->create();
sampler->setMinificationFilter(GL_LINEAR);
sampler->setMagnificationFilter(GL_LINEAR);
sampler->setWrapMode(Sampler::DirectionS, GL_CLAMP_TO_EDGE);
sampler->setWrapMode(Sampler::DirectionT, GL_CLAMP_TO_EDGE);

// float* mapData (in header)
mapData = new float[1024 * 1024];

for(int i = 0; i < 1024 * 1024; ++i)
mapData[i] = 0.0f;

m_funcs->glActiveTexture(GL_TEXTURE0);

TexturePtr heightMap(new Texture);
heightMap->create();
heightMap->bind();
heightMap->setImage(mapData, 1024, 1024);


Old code to set heightmap image data

void Texture::setImage(const QImage& image)
{
Q_ASSERT(m_type == Texture2D);

// convert to use only .bits, .width, .height
QImage glImage = QGLWidget::convertToGLFormat(image);
// glImage.bits() == uchar* QImage.bits()
glTexImage2D(m_type, 0, GL_RGBA, glImage.width(), glImage.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits());
}

New code to set heightmap image data

void Texture::setImage(float* pixelArray, int width, int height)
{
Q_ASSERT(m_type == Texture2D);

glTexImage2D(m_type, 0, GL_RGBA32F_ARB, width, height, 0, GL_RGBA32F_ARB, GL_FLOAT, &pixelArray[0]); // crash here!
}

What's incorrect on my new code?
Is generating of new mapData correct?

glararan
09-08-2013, 02:26 AM
Hi,

I'm posting my solution! Working perfect.


SamplerPtr sampler(new Sampler);
sampler->create();
sampler->setMinificationFilter(GL_LINEAR);
sampler->setMagnificationFilter(GL_LINEAR);
sampler->setWrapMode(Sampler::DirectionS, GL_CLAMP_TO_EDGE);
sampler->setWrapMode(Sampler::DirectionT, GL_CLAMP_TO_EDGE);

// mapData == in header float mapData[1024*1024*sizeof(float)]

for(int i = 0; i < 1024 * 1024 * sizeof(float); ++i)
mapData[i] = 0.1f * (qrand() % 5);

m_funcs->glActiveTexture(GL_TEXTURE0);

TexturePtr heightMap(new Texture);
heightMap->create();
heightMap->bind();
heightMap->setImage(&mapData, 1024, 1024);


void Texture::setImage(void* pixelArray, int width, int height)
{
Q_ASSERT(m_type == Texture2D);

glTexImage2D(m_type, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, pixelArray);
}