IneQuation.pl
11-20-2008, 09:47 AM
I have a GPU terrain renderer in my project based on Harald Vistnes's one from Game Programming Gems 6 (chapter 5.5). Basically, it's uploading a 17x17 flat, square patch to a VBO and using a vertex shader with a Vertex Texture Fetched-heightmap to deform it. The terrain grid is rendered as a quad tree, rendering the patch for each leaf with an offset and scale depending on LOD, passed as uniforms. This means that the same amount of verts/triangles is used to cover varying surface areas.
Back on topic. I've got it working with 16-bit heightmaps (using a GL_LUMINANCE8_ALPHA8 hack, as not all hardware supports GL_LUMINANCE16), but I'd like to extend hardware compatibility to SM3.0 cards, which only support 32-bit float formats for VTFing. The thing is, the heightmap gets clamped to the [0..1] range, and it doesn't even look like it's normalized against the highest value in the texture, the pixels look quite random.
The original Harald Vistnes's demo program for this technique uses Direct3D and a 32-bit float DDS texture for the heightmap, which means it's loaded natively, and there is no clamping. I'm guessing it's OpenGL's pixel transfer that's ruining it for me, as according to the spec, it's bound to clamp the incoming values to [0..1] no matter what. I can't find any way to disable this behaviour.
So the solutions that come to my mind are:
either upload the texture bypassing glTexImage2D, or normalize the heightmap before uploading and pass the scale and bias to shaders via uniforms.
Unless there is some way of disabling the clamping that I don't know of.
Now, of the two, the first approach seems more appealing to me. Are Pixel Buffer Objects the way to go here?
Any comments appreciated.
Back on topic. I've got it working with 16-bit heightmaps (using a GL_LUMINANCE8_ALPHA8 hack, as not all hardware supports GL_LUMINANCE16), but I'd like to extend hardware compatibility to SM3.0 cards, which only support 32-bit float formats for VTFing. The thing is, the heightmap gets clamped to the [0..1] range, and it doesn't even look like it's normalized against the highest value in the texture, the pixels look quite random.
The original Harald Vistnes's demo program for this technique uses Direct3D and a 32-bit float DDS texture for the heightmap, which means it's loaded natively, and there is no clamping. I'm guessing it's OpenGL's pixel transfer that's ruining it for me, as according to the spec, it's bound to clamp the incoming values to [0..1] no matter what. I can't find any way to disable this behaviour.
So the solutions that come to my mind are:
either upload the texture bypassing glTexImage2D, or normalize the heightmap before uploading and pass the scale and bias to shaders via uniforms.
Unless there is some way of disabling the clamping that I don't know of.
Now, of the two, the first approach seems more appealing to me. Are Pixel Buffer Objects the way to go here?
Any comments appreciated.