Sign in to follow this  
Hnefi

Displacement mapping help

Recommended Posts

Heyall. I need some help with displacement mapping. I've got a scene, which I render to a texture by using an FBO. I then map this texture onto a grid which is placed directly in front of the camera. The result is, of course, that it looks just like it would if I rendered directly onto the screen. I also have a vertex shader which is applied to each vertex of this grid (but currently does nothing except map the texture coordinates correctly). So far so good. I also have a second texture of equal size - my displacement map - which I occasionally render something to. Now, my problem is that I want to use my displacement map and let its RGB values determine how far my shader moves the affected vertices in the Z plane. In other words, for each vertex I want to obtain the RGB value from the pixel in my displacement map which is placed closest to this vertex and let my vertex shader use that value to manipulate the vertex it's currently operating on. The problem, of course, is that the texture data isn't available to me before I get to the fragment shading stage. I've tried using a "vertex texture fetch" technique described at http://developer.nvidia.com/object/using_vertex_textures.html, but that seems to assume I'm using cg, which I'm not - I'm using GLSL. Any ideas? If possible, I would like to use a technique that doesn't require a GF 6800 or better, but failing that, I'd be happy just knowing what the heck I need to do to make it work. Thanks in advance.

Share this post


Link to post
Share on other sites
true displacement mapping is not yet possible, as u cant create vertices

what youre describing can be done, it require the use of vertex textures (i forget there proper term) thus u DO need a gf6 and up (nv4x)

Share this post


Link to post
Share on other sites
Yes, I know the technique I'm currently trying to use requires a GF6xxx or better. But are there any techniques that don't require that generation of GPU but still produces pretty much the same effect when the mesh/texture is always viewed from directly in front of it?

Share this post


Link to post
Share on other sites
Hi Hnefi,

I've just read your description of the problem i have a little problem figuring out what you are trying to do. Do you want to displace the grid itself or the vertices of the scene?

1) If you are trying to displace the grid itself, i think this can be done with fragment programs by altering the depth of the fragment. Of course this may not look as good as with vertex textures, but it will work on older (than GF6x00) hardware. Again, i say that i don't understand your approach so forgive me if this is completely wrong.

2) If you are trying to displace the objects in the scene, i don't understand how the grid is going to help you. What data are you rendering in the scene texture and what data in the displacement texture? Are you rendering positions and offset vectors respectively? How dense is your grid? Is there a vertex for each pixel on the screen?

As for the nVidia's example, Cg isn't needed. It can't be a requirement for using vertex texture fetches, because Cg is using one of the NV_vertex_program_xx extensions as the final output, so if you support this, then vtf is supported. But i don't know how this is exposed under GLSL so i can't help. I would expect it worked fine, because as far as i know GLSL doesn't let you specify the final assembly profile (if it uses any). If your card supports vtf, then GLSL should support vtf (this is, tex2D instructions in a vp).

HellRaiZer

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this