Arinthian Posted January 8, 2014 Share Posted January 8, 2014 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. Quote Link to comment Share on other sites More sharing options...
shadmar Posted January 8, 2014 Share Posted January 8, 2014 your code seems to work ok, just make sure you look at them from above since backfaces are culled. ps! test and test_two also have the exact same position. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 8, 2014 Share Posted January 8, 2014 If you have applied shadmars changes and it still doesn't work, can you try out Copy() and see if it makes a difference. Quote Link to comment Share on other sites More sharing options...
Arinthian Posted January 8, 2014 Author Share Posted January 8, 2014 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 ) Quote Link to comment Share on other sites More sharing options...
Arinthian Posted January 8, 2014 Author Share Posted January 8, 2014 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. Quote Link to comment Share on other sites More sharing options...
Rastar Posted January 8, 2014 Share Posted January 8, 2014 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! Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 8, 2014 Share Posted January 8, 2014 You can also use the update button from the project manager. That way you don't have to create a new project. Quote Link to comment Share on other sites More sharing options...
Admin Posted January 8, 2014 Share Posted January 8, 2014 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. Quote Link to comment Share on other sites More sharing options...
Arinthian Posted January 8, 2014 Author Share Posted January 8, 2014 Wow, I never noticed that update button. it says "This project has no template specified" when I click it though. 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.