Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Tessellation heightmap

  1. #1
    Intern Newbie
    Join Date
    Dec 2011
    Posts
    47

    Tessellation heightmap

    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

  2. #2
    Intern Newbie
    Join Date
    Dec 2011
    Posts
    47
    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:
    Code :
        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:
    Code :
        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
    Code :
    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()
        [COLOR=#000000]glTexImage2D[/COLOR](m_type, 0, GL_RGBA, glImage.width(), glImage.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, glImage.bits());
    }

    New code to set heightmap image data
    Code :
    void Texture::setImage(float* pixelArray, int width, int height)
    {
        Q_ASSERT(m_type == Texture2D);
     
        [COLOR=#000000]glTexImage2D[/COLOR](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?

  3. #3
    Intern Newbie
    Join Date
    Dec 2011
    Posts
    47
    Hi,

    I'm posting my solution! Working perfect.

    Code :
        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);

    Code :
    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);
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •