19

Under D3D9 with XPDM you almost certainly want to instance wherever possible. Draw call overhead is just so high that it makes sense. In that scenario the crossover-point can be as low as 2 or 3 instances. If you've only got one instance of a given mesh, it may on the surface seem tempting to draw it non-instanced. However, look at what's involved: You ...


12

(On my system, didn't test it anywhere else) In GL, instancing a single mesh (drawing with count = 1) has some nasty overhead, but I don't know where it comes from. I strongly suggest not doing it. I tested this in a practical application a couple of months ago. I coded some global illumination algorithms in the Crytek Sponza scene, which consists of ...


10

since you admittedly don't have much experience with 3D and (presumably) OpenGL, I'll give you a "bird's eye" overview of the process. I'll do my considerations about OpenGL, but the basic reasoning yields for other APIs too. When you render something with a modern version of OpenGL you create objects that will reside into the GPU memory, and then mostly ...


5

According to the docs, glDrawArraysInstanced has the same effect as: if ( mode or count is invalid ) generate appropriate error else { for (int i = 0; i < primcount ; i++) { instanceID = i; glDrawArrays(mode, first, count); } instanceID = 0; } So it's basically a for-loop... But we need to take a step back and ask the ...


5

Instantiate creates it as a game object thus loosing the prefab link. You want to use PrefabUtility.InstantiatePrefab() in order to spawn the object in the scene and maintain the prefab link.


5

Gather the instances into a collection as you instantiate them. Then you can iterate over all members of the collection anytime you want, with no search overhead. public class MyType : MonoBehaviour { static List<MyType> allOfMyType = new List<MyType(); void Awake() { allOfMyType.Add(this); } void OnDestroy() { ...


4

Your performance hit come from driver overhead (state changes). Having 50K VAOs is wayyyyy too much. If all your models are the same format (for example the format x,y,z,r,g,b,a) then you should use one VAO and one VBO. You can use something like glMultiDrawArraysIndirect for rendering large amounts of object and you can create commands (which require no ...


4

There are two main ways to get instance data into a shader program: Setting the instance divisor for one or more vertex attributes (instead of advancing every vertex, it will advance every N instances) Using gl_InstanceID or an instanced attribute to select part of an array of instance data stored in a uniform buffer, shader storage buffer, etc. ...


3

DXGI_FORMAT_R32G32B32_FLOAT is not 16 bytes, that's the first problem after a quick look. Either declare it 12 in your layout or specify D3D11_APPEND_ALIGNED_ELEMENT instead. Or Make it DXGI_FORMAT_R32G32B32A32_FLOAT instead depending on your matrix.


3

I agree with petterson, but if you want to reduce amount of draw calls as well you need to use instancing. Does my approach look good? If you create it once and will not move a lot of stuff around each frame, there is nothing bad in it. It all depends on you usage. How do I manage positions per mesh? For this you need to identity what mesh is ...


3

From the easy to the scalable and complex to implement, kind of: A fast to write option is simply to let the HUD know where the player is and let it grab what variables it needs directly. It's not very flexible, but for games where the player is well defined and the scope of the game is tightly contained it can work well enough. This is a tightly coupled ...


3

Instancing is an improvement relative to multiple draw calls, with state changes between each draw. Instancing exists to allow you to provide per-instance data to each instance, so that it can iterate over the same vertices with new data. This allows you to do things like provide offsets or even full transformation matrices to each instance of vertices, all ...


3

TL;DR: Edit your shader compilation to use Shader Model 5.1 or later. With the DirectX 12 API, there is no supported device to date that supports anything less than Direct3D Feature Level 11.0. Therefore, there is no point in using any of the down-level profiles lower than 5.1. See Microsoft Docs The default in most UWP templates if you don't set an ...


2

In general terms, you're talking about the difference between the Factory pattern - a piece of code that creates objects based on being told which type to make - and the Prototype pattern - a piece of code that creates objects by copying an existing object. In cases like this, I think the prototype pattern is the wrong way to go. A rocket will have several ...


2

First of all, OpenGL is full of weird things so a driver bug, however unlikely it may be, is still an option - consider testing the app on different setups (nVidia vs. AMD, older drivers) and other tiny modifications of code. For example, you could start with removing the "glBindBuffer(GL_UNIFORM_BUFFER, 0);" line - it appears to be doing nothing useful ...


2

This is not really dynamically coloring but you can alter the lighting effects to achieve the same thing. The AmbientLightColor effect should work. effect.AmbientLightColor = new Color(r, b, g); Also there is an effect.alpha that you use for transparency iirc which takes a float between 0-1.


2

You shouldn't be attempting to instance individual cubes at all. I developed Techcraft together with two close dev friends. It has all the sample code you will need to learn from, if it helps. Feel free to download the source code and use as you wish: http://techcraft.codeplex.com Good luck! Hopefully we can add your game to the list on the project page.


2

Instancing requires to change the InputLayout of vertex buffers and pass an instancing buffer along the mesh vertices. Unfortunately, there is nothing automatic to do this with Toolkit models, though possible but would require to dig into the internals to do this yourself. Before even trying to do some instancing with models, you should start with a basic ...


2

What you'll wind up doing David is creating a vertex buffer to hold the different transformation matrices for each instance of grass. You will need a vertex declaration that has your standard 'grass' vertex components( pos, norm, uv...etc ), and in that same declaration 4 additional 4-component floats to hold the 4x4 transformation matrix...the declaration ...


2

The DirectX SDK has samples on how to do this, and there are resources online you can find on how to do this. Look in C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Samples\C++\Direct3D\Instancing\Instancing.cpp. Here's a Nvidia GPU Gem article on Geometry Instancing. And here's an article on MSDN. This article shows you the two vertex ...


2

It's been 4 years... and I think its safe to say that is perfectly fine to submit "instanced" draw calls with 1. As you may have noticed, new APIs DX12 and Vk both have an instance count that can be from 0 to NUM_INSTANCES. Also note that there is no DrawIndexed(...). EDIT As a note of caution, the above is probably fine with this modern APIs, maybe using ...


2

You can be for certain that drawing a single object instanced is more expensive than drawing a single object normally. For instancing the GPU is preparing for a large amount of objects and this preparation will be different than for a single object. However how large this performance gap is can only be found by experimenting and is very much depending on ...


2

So, I am going to assume that all the instances share the same model data (vertex positions, vertex normals.) In that case, the Divisor() call is incorrect: currently you tell OpenGL that each instance has its own normal: this is typically incorrect: the instances share positions and normals, and have a matrix each. The slots for the attributes don't ...


2

I know this question was asked prior, but with OpenGL 4.6 you can now call glDrawArraysInstancedBaseInstance to do exactly what was asked. Another option is with OpenGL 4.2 the ARB_base_instance extension was added for this as well. So to draw tree 3, 65, 89 and 95 you could make 4 draw calls of size 1 instance and put the offsets for each


2

Looking at the WebClient docs, the method is described as: Downloads a string from a resource, without blocking the calling thread. and given the error message: INTERNAL_CALL_Internal_InstantiateSingle can only be called from the main thread It's clear that you need to download the data and store it, and only call DisplayCells, in the main thread, ...


2

Very simple: "non-GPU" instancing doesn't exist. Doing more work on the GPU is the whole point of instancing. Moreover, instancing improves performance by reducing the amount of data that has to be pushed to the GPU and hopefully by reducing CPU computations, at the price of doing more work on the GPU: it doesn't have "alleged GPU advantages".


2

There is never one "right" or "wrong" way to do something in programming. Just ways which do or do not work for you, your team and your project. So don't worry about doing things the right way, worry about writing a program you can still understand, change and extend later. The pattern from the question has some implications for later maintainability. When ...


2

void BreakAsteroidInHalf() { GameObject tempAsteroid = Instantiate(asteroidPrefab); tempAsteroid.transform.position = transform.position; tempAsteroid.transform.Rotate(0, -45, 0); tempAsteroid.transform.localScale *= 0.5f; tempAsteroid.GetComponent<Asteroid>().sizeKey -= 1; GameObject tempAsteroid2 = Instantiate(asteroidPrefab2)...


Only top voted, non community-wiki answers of a minimum length are eligible