Jump to content

Help with API needed: Drawing meshes


Rastar
 Share

Recommended Posts

Somehow I can't find the right API calls for what I would like to do:

 

1) Define a couple of vertex and index buffers. These are used as generic patches for a displacement mapped terrain. I therefore only need 2D vecs, but of course 3D vecs are OK as well.

2) Draw these several times during a frame update, each with a different position and/or scale.

 

The only place I could find to define vertex and index buffers is the Surface class. But if I use it as part of a model (created by Model::AddSurface() ) I don't know how to reuse the patches. If I try to use stand-alone Surfaces (Surface::Create() ) without adding them to a model, my program crashes.

 

Is there a way to do this?

Link to comment
Share on other sites

Something like this would create a 2 triangle plane:

 

local patch = Model:Create()

local surface = patch:AddSurface()

surface:AddVertex(-0.5,-0.5,0, 0,0,-1)

surface:AddVertex(0.5,-0.5,0, 0,0,-1)

surface:AddVertex(0.5,0.5,0, 0,0,-1)

surface:AddVertex(-0.5,0.5,0, 0,0,-1)

surface:AddTriangle(2,1,0)

surface:AddTriangle(0,3,2)

 

patch:SetColor(1,1,0)

 

Then maybe instance more of them and rescale them :

 

local patch2 = patch:Instance()

patch2:SetScale(2)

patch2:SetColor(1,0,0)

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Ah, thanks, I wasn't aware of the Instance() member. But will this actually create a second vertex and index buffer? I like to draw the same set of vertices several times, since they're only the regular mesh to be displaced in the shader.

Link to comment
Share on other sites

No, this would be the same mesh since it instanced from the first one. (not a copy, but an instanced one)

You can do the same using a loaded mesh, and just instance it several times, then use a vertex shader to displace height.

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Creating instances will be faster because they will be rendered in a batch. This is one of the tricks Leadwerks uses for terrain...the landscape is split into identical patches and the heightmap texture is used to control the height offset.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...