Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Heightmap Per Quad


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 multifractal   Members   -  Reputation: 229

Like
0Likes
Like

Posted 25 July 2013 - 09:37 PM

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.

Sponsor:

#2 Chris_F   Members   -  Reputation: 2434

Like
0Likes
Like

Posted 25 July 2013 - 11:25 PM

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



#3 Norman Barrows   Crossbones+   -  Reputation: 2204

Like
0Likes
Like

Posted 25 July 2013 - 11:35 PM

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


Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 


#4 multifractal   Members   -  Reputation: 229

Like
0Likes
Like

Posted 27 July 2013 - 10:00 PM

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? 



#5 Norman Barrows   Crossbones+   -  Reputation: 2204

Like
1Likes
Like

Posted 28 July 2013 - 01:58 PM


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, 28 July 2013 - 02:00 PM.

Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 


#6 multifractal   Members   -  Reputation: 229

Like
0Likes
Like

Posted 29 July 2013 - 02:22 AM

 


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, 29 July 2013 - 02:41 AM.


#7 Norman Barrows   Crossbones+   -  Reputation: 2204

Like
0Likes
Like

Posted 29 July 2013 - 12:41 PM


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).


Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS