I success to generate the height map using texture in openGL. The full picture of this data is shown in the figure below. However, when I'm using GL_LINEAR option in my glTexParameteri (MinMag) it give me outer artifacts.
this is my glTexParameter
if (interpolate) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Here is my fragment shader code
"varying vec2 tex;\n"
"uniform int colorSizeI;\n"
"uniform vec4 colorTable[512];\n"
"uniform vec2 minmaxZ;\n"
"uniform vec3 backgroundColor;\n"
"uniform sampler2D diffuse;\n"
"uniform float transparency;\n"
"void main() {\n"
" float color = texture2D(diffuse, tex).r;\n"
" float h = (color - minmaxZ[0])/(minmaxZ[1] - minmaxZ[0]);\n"
" float colorSizeF = float(colorSizeI);\n"
" int i = 0;\n"
" float j = 0.0f;\n"
" vec3 base;\n"
" if (color == 0.0f) {\n"
" base = vec3(0.0f, 0.0f, 0.0f);}\n"
" else if (color <= minmaxZ[0]) {\n"
" base = colorTable[0].xyz;}\n"
" else if (color >= minmaxZ[1]) {\n"
" base = colorTable[colorSizeI - 1].xyz;}\n"
" else { \n"
" while (h >= (j + 1.0f)/colorSizeF) {\n"
" i += 1;\n"
" j += 1.0f;}\n"
" base = mix(colorTable[i].xyz, colorTable[i+1].xyz, colorSizeF*(h - (j/colorSizeF)));}\n"
" gl_FragColor = vec4(base, transparency);\n"
"}\n";
Here is the image when using GL_Nearest (everything is OK)
Here is the image when using GL_Linear (outer interpolated artifacts comes out)
So, anyone know how to remove this artifacts ?
NB: The outer black color is consider the data also when color = 0.