Hello,

I am developing a terrain fractal generator based on an original heightmap of 256*256. Each point in the height map contain the height but also gradient on X and gradient on Y. These are inputs to my program.
I want to send this heightmap in the shader and access it's values in the vertex shader. That is, because I cannot compute the elevation given X and Y ( Z is upwards ) unless I can compute the cell in which the XY is located and then compute the elevation based on the height and gradients.
I have used the following basic code:

Code :
glEnable( GL_TEXTURE_2D );glGenTextures(1, &m_uglID);
glBindTexture(GL_TEXTURE_2D, m_uglID);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB, 256, 256);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 256, GL_RGB, GL_FLOAT, pvBytes);
 
...
 
m_ugl_HeightMapTexture = glGetUniformLocation(m_uglProgram, "TexHeightMap");
 
...
 
glEnable(GL_TEXTURE_2D );
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D , pTexture->GetID());
glUniform1i(m_ugl_HeightMapTexture, 0);

shader code:

Code :
uniform sampler2D TexHeightMap;
vec4 GetVertCellParameters( uint i, uint j )
{
    return texture( TexHeightMap, vec2( i, j ) );
}
...
    vec4 vH00 = GetVertCellParameters( i, j );
    vec4 vH10 = GetVertCellParameters( i + 1u, j );
    vec4 vH01 = GetVertCellParameters( i, j + 1u );
    vec4 vH11 = GetVertCellParameters( i + 1u, j + 1u );


Code doesn't work ( cannot send the actual data to the shader ), unless data contain only positive values. I need a way to get the whole heightmap ( together with gradients ) to the shader.