Rastar Posted August 22, 2013 Share Posted August 22, 2013 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? Quote Link to comment Share on other sites More sharing options...
shadmar Posted August 22, 2013 Share Posted August 22, 2013 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) 1 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Rastar Posted August 22, 2013 Author Share Posted August 22, 2013 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. Quote Link to comment Share on other sites More sharing options...
shadmar Posted August 22, 2013 Share Posted August 22, 2013 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. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Admin Posted August 23, 2013 Share Posted August 23, 2013 This is pretty much exactly what the built-in terrain system does. Quote Link to comment Share on other sites More sharing options...
Rastar Posted August 23, 2013 Author Share Posted August 23, 2013 Is an instancing call expensive? I need many of those patches, can I instance them each frame update, or should I store the instances ( which would make the code less elegant)? Quote Link to comment Share on other sites More sharing options...
Admin Posted August 23, 2013 Share Posted August 23, 2013 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. Quote Link to comment Share on other sites More sharing options...
Rastar Posted August 23, 2013 Author Share Posted August 23, 2013 Yes, but do create the instances in the Draw() call, or do you create them during initialization and store them in an array? Quote Link to comment Share on other sites More sharing options...
Admin Posted August 23, 2013 Share Posted August 23, 2013 Create them once, ahead of time! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.