Texture for Heightmap

Started by
9 comments, last by JohnnyCode 8 years, 11 months ago
I'm trying to find a way to make textures that store at least 1 component of color with good accuracy.

I generate the texture like this:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, TEXTURE_SIZE, TEXTURE_SIZE, 0, GL_RGBA, GL_FLOAT, 0);

Then I fill in the data with a compute shader.

I bind the texture like this:
glBindImageTexture(1, texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);


And save the data in the shader like this:
imageStore(destTex, c, height.xyz);

This produces terrain that looks like steps since my terrain is large and tall. I assume this because each color gets 8 bits. Is there a way to get more precision for at least the red component and be space efficient?
Advertisement

There is GL_R32F/I/UI internal texture format (32 bit precision) and GL_RED external format (thus you wont waste space for unneccessary channels).

Plus you can apply some kind of smoothing algorithm to your heightmap (if you havent yet).

There is GL_R32F/I/UI internal texture format (32 bit precision) and GL_RED external format (thus you wont waste space for unneccessary channels).

Plus you can apply some kind of smoothing algorithm to your heightmap (if you havent yet).

I tried your suggestion:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, TEXTURE_SIZE, TEXTURE_SIZE, 0, GL_RGBA, GL_FLOAT, 0);

is now

glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, TEXTURE_SIZE, TEXTURE_SIZE, 0, GL_RED, GL_FLOAT, 0);

glBindImageTexture(1, texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);

is now

glBindImageTexture(1, texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32F);

This however provides extremely different results. Is there anything I would have to change elsewhere?

Sorry I am relatively new to opengl.

Well what is the data you are uploading? If your old data was a bitmap then your data uploading isn't GL_FLOAT.....

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Well what is the data you are uploading? If your old data was a bitmap then your data uploading isn't GL_FLOAT.....

The original data is NULL.

I fill it in with a compute shader.

What do you mean by extremely different results? Your changes seem ok, maybe you forgot to change glGetTexImage code, didnt you? Or if you use this texture in some shader, check how you bind it.

What do you mean by extremely different results? Your changes seem ok, maybe you forgot to change glGetTexImage code, didnt you? Or if you use this texture in some shader, check how you bind it.

I use it in a shader. The bindings don't seem to need to change in any way:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
I tried just writing .3 and .8 to the red channel and rendering the texture to screen with a full screen quad. The colors are same when I use R32_F. When I use RGBA8 the .8 renders brighter.
When I use my noise function for terrain, R32_F produces some very erratic terrain.

I use it in a shader. The bindings don't seem to need to change in any way:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
I tried just writing .3 and .8 to the red channel and rendering the texture to screen with a full screen quad. The colors are same when I use R32_F. When I use RGBA8 the .8 renders brighter.
When I use my noise function for terrain, R32_F produces some very erratic terrain.

Well, everything seems ok. Try glGetTexImage(GL_TEXTURE_2D, 0, GL_RED, GL_FLOAT, data) to see if your test texture contains correct values after compute shader.

Make sure you've set the image format correctly in your GLSL shader as well. E.g.

#version 410 core
 
layout(r32f) image2D destTex;
 
void main() {
  // ...
  imageStore(destTex, o, height.xyz);
}

Make sure you've set the image format correctly in your GLSL shader as well. E.g.


#version 410 core
 
layout(r32f) image2D destTex;
 
void main() {
  // ...
  imageStore(destTex, o, height.xyz);
}

I've done that too.

I think I'll just use a buffer of floats instead of a texture.

This topic is closed to new replies.

Advertisement