per pixel displacement mapping

Started by
24 comments, last by jeroenb 18 years, 6 months ago
Quote:
just curious, how fast is this thing? I remember when I was reading that GPU Gems chapter I was immediately put off by the 3D texture and the precomputation involved. Have you considered relief mapping?


Like AndyTX mentioned it's pretty fast on my Geforce6 machine. On slower machines (SM 2.0) I use two steps which gives me much nicer results than offset/parallax Mapping.

I think it could also be possible to put the 3D texture into a big 2D texture using AtlasTexture Tools if you want to prevent 3D-textures.

Why don't you like the precomputation? It's just a texture which you have to prepare like other textures for your game/visualisation. And with the right tools it can be automate, like "click, wait,... done" :)

@AndyTX: do you think my tool creates the right distance map?
Advertisement
well pre-computation generally limits algorithms in certain cases, i.e. they are not very flexible. For example, if the height field changes dynamically you basically cannot apply this technique. Sure you can animate the height field by storing this 3D texture for every keyframe but is that really feasible? :P
Quote:Original post by bebud
@AndyTX: do you think my tool creates the right distance map?

I really don't know - I'd have to look at it in more detail. You're going to have to wait for Will to get back to you on this one :)

From the images you posted, I am fairly confident that you are not computing the distance map correctly. Recall that if you have a height map h, the value of the distance map d(x,y,z) is the minimum distance between (x,y,z) and any other point (u, v, h(u,v)). It looks as though the result you are getting is the distance between (x,y,z) and h(x,y). The distance map computation code that I cooked up with Stefanus is available online from NVIDIA at http://download.nvidia.com/developer/GPU_Gems_2/CD/Index.html and I would suggest comparing your results with ours to see the difference.

As for the black layers, your bottom layer should always be black. This ensures that the ray always terminates, otherwise it could cause some very odd artifacts. But two black layers just means you are wasting data.

Glad you liked the chapter, and hopefully this will help you get it working better.

Will.
"Math is hard" -Barbie
Hey!

Thanks a lot...I'll have a look at it today :)
I am looking at this chapter too and I am trying to implement it with OpenGL and CG but I cant get the displacement working. I use the distance.cpp file that comes with the chapter sources. There is no compiler error, but the displacement does not happen, only the normal mapping. For filling the distance texture I use the glTexImage3D function:

glTexImage3D(GL_TEXTURE_3D, 0, 1, width, height, depth, 0, GL_RED, GL_UNSIGNED_SHORT, final.m_data);


final is an instance of the DistanceMap structure, filled with almost the same code as in the original file:

   DistanceMap final(width, height, depth, 1);   for (int z = 0; z < depth; z++) {      for (int y = 0; y < height; y++) {         for (int x = 0; x < width; x++) {            double value = 0;            for (int i = 0; i < 3; i++) {               value += dmap(x, y, z, i)*dmap(x, y, z, i);            }            value = sqrt(value)/depth;            if (value > 1.0) value = 1.0;            final(x, y, z, 0) = value;         }      }   }


The CG code is exactly the same as comes with the chapter sources. I guess there is something wrong with the glTexImage3D call.

I searched for the Danielsson paper, but I couldn't find it. Does one of you have a reference to it?

Crafter 2D: the open source 2D game framework

?Github: https://github.com/crafter2d/crafter2d
Twitter: [twitter]crafter_2d[/twitter]

Seems that something is wrong with my call to the glTexImage3D function. Even when I set every color to the maximum I get no replacement. I checked my videocards capabilities and it should support 3D texture with sizes up to 512 (GeForce6).

GLuint id;   glGenTextures (1, &id);   glGetError();   glTexImage3D(GL_TEXTURE_3D, 0, 3, width, height, depth, 0, GL_RGB, GL_UNSIGNED_BYTE, final.m_data);   int error = glGetError();   if (error != GL_NO_ERROR) {      cerr << gluErrorString(error) << endl;   }


final.m_data contains the data which should be loaded into my texture. In my fragment shader it tells me (by coloring red) that for every texel the contents of this map is 0. I don't realy know how to proceed from here..

Anyone an idea what could be wrong here?

Crafter 2D: the open source 2D game framework

?Github: https://github.com/crafter2d/crafter2d
Twitter: [twitter]crafter_2d[/twitter]

Quote:Original post by jeroenb
[...]
   GLuint id;   glGenTextures (1, &id);   glGetError();   glTexImage3D(GL_TEXTURE_3D, 0, 3, width, height, depth, 0, GL_RGB, GL_UNSIGNED_BYTE, final.m_data);   int error = glGetError();   if (error != GL_NO_ERROR) {      cerr << gluErrorString(error) << endl;   }
[...]
Anyone an idea what could be wrong here?
You aren't binding the texture before you try to upload data to it.
I added the bind call, but it still did not work. I will have another indepth look at it tomorrow, but anyone has an idea I am all open for it :)

Crafter 2D: the open source 2D game framework

?Github: https://github.com/crafter2d/crafter2d
Twitter: [twitter]crafter_2d[/twitter]

Update:

I got things almost running. But for some strange reasons the bumpdepth isn't working as in the demo. When increasing the depth, nothing changes during the run. Even not when I hardcode it in the vertex program.

Crafter 2D: the open source 2D game framework

?Github: https://github.com/crafter2d/crafter2d
Twitter: [twitter]crafter_2d[/twitter]

This topic is closed to new replies.

Advertisement