Sign in to follow this  
multifractal

Heightmap Per Quad

Recommended Posts

Hello,
I am struggling with the idea of generating a heightmap and normal map per quad on a single mesh. Currently I am using openCL to generate these maps and was planning on sending these textures to the vertex/frag shaders in order to modify the vertices and apply the lighting. But I see no way of doing this other than making each quad an individual mesh which I don't think is very efficient (managing ~400 meshes or so). So I was wondering if there were any other ways of doing this.
Any suggestion is hugely appreciated.

Share this post


Link to post
Share on other sites

Instead of making each quad a mesh, you could make each quad have unique vertices and then use a texture array. Are you trying to implement PTEX? I'd like to see hardware/driver support for it in future versions of D3D/OpenGL.

 

https://developer.nvidia.com/sites/default/files/akamai/gamedev/docs/Borderless%20Ptex.pdf

Share this post


Link to post
Share on other sites

you assemble individual quad meshes into a single big mesh of quads in regular ram with the cpu. then you copy them to dynamic buffers in vidram and draw:

 

for each quad:

translate to desired location in a larger mesh (say 10x10 to 100x100 quads) heightmap, and add to a vertex buffer / index buffer in RAM.

 

once done, lock a dynamic VB and IB allocated in vidram and memcpy the RAM copies to the vidram buffers. 

 

then draw using those.

 

 

i use a similar method:

for each ground texture N in a 300x300 terrain chunk:

      for each 10x10 quad X,Z in the chunk that uses texture N: 

            translate master copy of quad mesh to correct position in the terrain chunk

            heighmap quad

            add quad X,Z to ground mesh N

copy ground mesh N to a static VB and IB

draw per usual

Share this post


Link to post
Share on other sites

Instead of making each quad a mesh, you could make each quad have unique vertices and then use a texture array. Are you trying to implement PTEX? I'd like to see hardware/driver support for it in future versions of D3D/OpenGL.

 

https://developer.nvidia.com/sites/default/files/akamai/gamedev/docs/Borderless%20Ptex.pdf

No nothing that cool; just procedural terrain, 

 

 

you assemble individual quad meshes into a single big mesh of quads in regular ram with the cpu. then you copy them to dynamic buffers in vidram and draw:

 

for each quad:

translate to desired location in a larger mesh (say 10x10 to 100x100 quads) heightmap, and add to a vertex buffer / index buffer in RAM.

 

once done, lock a dynamic VB and IB allocated in vidram and memcpy the RAM copies to the vidram buffers. 

 

then draw using those.

 

 

i use a similar method:

for each ground texture N in a 300x300 terrain chunk:

      for each 10x10 quad X,Z in the chunk that uses texture N: 

            translate master copy of quad mesh to correct position in the terrain chunk

            heighmap quad

            add quad X,Z to ground mesh N

copy ground mesh N to a static VB and IB

draw per usual

So I should generate each quad as an individual mesh and then insert the vertex buffer into the parent mesh? 

Share this post


Link to post
Share on other sites

So I should generate each quad as an individual mesh and then insert the vertex buffer into the parent mesh? 

 

i have a "master quad" in ram, a RAM vb and ib for the big mesh of qauds, and a VB/IB in vidram.

 

the master quad is just a quad from 0,0,0 to 10,10,0.

 

first i transform the master quad values to the proper location, then heightmap them add them to the big quad in ram.

 

so let's say i'm adding the quad at x=50, z=20. i add 50 to the x of all 4 verts, and 20 to the z of all 4 verts. i pass the results to my heightmap function which returns my y values at those locations. then i pass all those results as the verts of the quad to add to the big mesh.

 

so i don't generate a quad each time i add one. i just repeatedly transform the one master quad generated at program start.

 

note that the master quad, and VB / IB in ram are just arrays of floats, not D3D data structures. only the VB/IB in vidram is a D3D data structure.

Edited by Norman Barrows

Share this post


Link to post
Share on other sites

 


So I should generate each quad as an individual mesh and then insert the vertex buffer into the parent mesh? 

 

i have a "master quad" in ram, a RAM vb and ib for the big mesh of qauds, and a VB/IB in vidram.

 

the master quad is just a quad from 0,0,0 to 10,10,0.

 

first i transform the master quad values to the proper location, then heightmap them add them to the big quad in ram.

 

so let's say i'm adding the quad at x=50, z=20. i add 50 to the x of all 4 verts, and 20 to the z of all 4 verts. i pass the results to my heightmap function which returns my y values at those locations. then i pass all those results as the verts of the quad to add to the big mesh.

 

so i don't generate a quad each time i add one. i just repeatedly transform the one master quad generated at program start.

 

note that the master quad, and VB / IB in ram are just arrays of floats, not D3D data structures. only the VB/IB in vidram is a D3D data structure.

 

Oh ok that makes a lot of sense. So originally I was sampling the heightmap in a vertex shader and then doing normal mapping in a pixel shader. Would this be possible the method you described?

Also should the "master quad" be start out as the maximum size a quad could be or should there be a quad for every differently sized quad?

Edited by multifractal

Share this post


Link to post
Share on other sites


Oh ok that makes a lot of sense. So originally I was sampling the heightmap in a vertex shader and then doing normal mapping in a pixel shader. Would this be possible the method you described?

 

the heightmap can be applied to the mesh in RAM before you send it off to directx for drawing, or you can use the vertex shader to apply the heightmap. the most efficient way will depend on your particular application.

 

 


Also should the "master quad" be start out as the maximum size a quad could be or should there be a quad for every differently sized quad?

 

if you have multiple sizes of quads, you can just scale a single unit sized master quad, or have a master copy of each size. a master copy for each size avoids the performance hit of one scaling operation per quad. it may also make the code simpler (or perhaps not). either way you have to track which scale or quad size to use.

 

i tend to use a CSG type of approach to drawing, so i'd probably just have a single unit quad that i scaled as needed for all quads in the game. the performance hit for one scaling operation per quad isn't that bad. especially compared to the drawing time for one quad.

 

as usual it depends on how you do things. you could use the CPU for transforming and the GPU for drawing, or you can do it all on the GPU with shader code. splitting the work between the CPU and GPU may be faster, or the GPU alone may be faster.

 

for best results, i suspect you'll want to recalculate the normals after heightmapping, but before applying lighting. at the moment i just leave mine at (0,1,0).

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