Jump to content

Instancing in Steam Indie Version


Arinthian
 Share

Recommended Posts

Hello,

 

I've been working on a top down shooter style game, and I've been wanting to use instancing for projectiles from the player (generally just quads right now) but I've been having trouble getting the Instance() function to work like I wanted, and I have no clue how to use the GPU instancing (which I believe is now supported in this version?)

 

this is how I've been trying to use the Instance() function

 

local test = Model:Create()
test:SetPosition(0, 0, 0)
test:SetColor(1, 1, 1)

local material = Material:Create()
material:SetColor(1, 1, 1)
material:SetShadowMode(false)

local s = 2

local ratio = 2

local surface = test:AddSurface()
surface:AddVertex(-s, 0, -s*ratio, 0, 0, -1)
surface:AddVertex(s, 0, -s*ratio, 0, 0, -1)
surface:AddVertex(s, 0, s*ratio, 0, 0, -1)
surface:AddVertex(-s, 0, s*ratio, 0, 0, -1)
surface:AddTriangle(2, 1, 0)
surface:AddTriangle(0, 3, 2)

test:SetMaterial(material)

test:UpdateAABB(Entity.LocalAABB)
test:UpdateAABB(Entity.GlobalAABB)

local test_two = test:Instance()
test_two:SetPosition(0, 0, 0)

local test_three = test:Instance()
test_three:SetPosition(5, 5, 5)

 

which seems to just move the one model around rather than drawing several in different locations.

 

Any help or guidance would be greatly appreciated, especially in the matter of the GPU instancing, since I might as well take advantage of that if possible.

Link to comment
Share on other sites

I've already got the camera looking from above, set from another script.

 

I also tried SetBackFaceCullMode(false) on the material, to see if that helped. it didn't.

 

I switched Instance() to Copy(), and I can see all three quads (after setting the second to a different position, of course :P )

Link to comment
Share on other sites

I figured it out.

 

seems that because the project I created was from before the launch, the changes weren't reflected in my

project. creating a new project and using the same code works fine with Instance()

 

EDIT: just in case you were curious what the change was, it was just a simple line in the shader

 

from

 

mat4 entitymatrix = entity.matrix[0];

 

to

 

mat4 entitymatrix = entity.matrix[gl_InstanceID];

 

So I'm assuming it automatically uses GPU instancing, which is awesome.

Link to comment
Share on other sites

Whoaaa, hang on, does that mean that hardware instancing is automatically taking place? Always, or as soon as gl_InstanceID is used in a shader for the object?

 

I guess we really need some clarification here from Josh how this works!

It's always taking place, with the exception of animated models, although there is a way we could instance up to 60 of those...future development.

 

 

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