32

It really depends on the technique. In a forward render you often have one shader for every different material type. In AAA games that use this technique shaders are often generated from a set of options on the material which an artist can set. This can lead to hundreds of shaders(1). But lets say generally the number of shaders is in the order of 40 In a ...


24

Yes, a game engine will in general have a variety of different shaders. The typical pattern is: While initializing the engine and loading the game world, prepare all the shaders you will use for rendering. By "prepare" I mean load them into memory, compile them if necessary, and do all the ID3D11Device::CreatePixelShader and similar calls to get ...


15

Yes. You can initialize the Direct3D device using D3D11CreateDevice, which requires no window. You simply do not create a swap chain at all. You can still create offscreen render targets and draw to them in the usual way. Instead of calling Present on the swap chain, you can call ID3D11DeviceContext::Flush to kick the GPU with the work you've queued up. ...


11

There's a good presentation about this: Don't Throw It All Away: Efficient Buffer Management by John McDonald at NVIDIA. It covers various topics, but on the subject of your question, the general advice is to create buffers with dynamic usage and use Map() with D3D11_MAP_WRITE_DISCARD, when the data needs to be updated frequently (like every frame, or ...


10

The Sample method accepts a UV coordinate (where the texture covers the [0, 1] range), does mipmap selection based on the UV derivatives, applies addressing modes (clamp, wrap, border) and does filtering (bilinear, trilinear, aniso). The Load method accepts a texel coordinate in the [0, textureWidth - 1] x [0, textureHeight - 1] range, and the desired mip ...


8

You have to create the threads yourself, using your threading library of choice (boost, C++11 async, Windows threads, etc). The idea is that you will create several threads and split up your CPU rendering work amongst them. Each thread uses a D3D11 deferred context to accumulate all the D3D11 commands (state changes, draw calls, etc.) it wants to execute. ...


8

Typically, branching of any kind (switches, if-statements, loops with non-constant iterations) are best avoided. This is mildly true on the PC (not enough to be worth worrying about at all outside of very tight inner loops), especially true on some general-purpose CPUs like the 360's Xenon (common hardware that makes indirect references on branches ...


8

The FBX documentation is painful at times, and this is definitely one of them. There are two ways I've used to access animation data. The first is used in the ImportScene sample that comes with the SDK, and it's the way you seem to be trying to do things. In your sample, now that you have a valid lAnimCurve, you would need to query the number of keyframes ...


8

No, at least in D3D11 it is not possible to change the size of a buffer or texture after it's been allocated. You would have to release the old buffer and create a new one (which is inadvisable to do often, as it can hurt performance). It's okay to only use part of a vertex buffer, so if you know the maximum size your data will be, I'd allocate the buffer ...


8

The "DirectX" project templates are for Windows Store Apps / Windows Phone Apps. So I assume it has to do with the version of VS Express you are using (Desktop). However, you don't need anything special to write traditional desktop apps. You just need to create a Win32 Application and include the DX11 headers in your code


7

Yes, you can do this with d3d11 shader reflection. Here is some code showing how to iterate over a constant buffer, as well as grab all the values within the cbuffer. This doesn't require you to know anything about the shader. ID3D11ShaderReflection* reflection = NULL; D3D11Reflect(description->buffer, description->length, &reflection); ...


7

There are two ways to set the stencil buffer value in Direct3D 11, one of which is only available in Direct3D 11.3 (and Direct3D 12). I will split this answer into two parts accordingly. Direct3D 11 General As part of the D3D11_DEPTH_STENCIL_DESC you specify what action to take on a stencil test pass and fail. These options boil down to: Keep the current ...


7

Use several constant buffers and group variables together based on how often they change. If your variables are fairly static ( or just huge ) you may be better off converting values into a texture and extracting them in the shader.


7

The world matrix translates the coordinates of your vertices from model space to world space. This transformation includes the position of the object in the world as well as its orientation and potentially scale. The view matrix translates those vertices from world space to camera/view space. This means the transformed coordinates are in relation to the ...


7

The range [-1 ; 1] x [-1 ; 1] x [0 ; 1] mentioned in the tutorial refers to the canonical view volume. It is the final coordinate space vertex data gets mapped to before everything is rasterized to your screen. To understand what exactly this means, it helps to take a look at what a rendering pipeline typically looks like. Coordinate spaces A coordinate ...


6

System memory also loses power during hibernation, as the system is completely powered off during hibernate. Windows deals with both system memory and video memory the same way: it dumps them to disk. Hence, it is only copying out video memory when necessary, when hibernation is invoked. If you meant stand-by mode, where the system is put into low-power ...


6

You need to make sure that any variable you use within the constant buffer does not cross a 16 byte alignment boundary, or you won't be able to access it from the shader. For example, you could have a constant buffer that looks like this: struct constant_buffer { XMFLOAT4X4 wvp; // 64 bytes -> 16 byte aligned = OK XMFLOAT3 position; // 12 ...


6

Well, I'm surprised about the stuff you can learn when researching stuff for answering a question. Short answer: you can't. This stuff you probably already know, but I'll cover it in case other people find it useful. At first I thought you can't share handles among Direct3D devices, let alone versions, but it turns out that you can actually do that! In ...


6

Multiple vertex buffers would be used when your data is non-interleaved. If your data was interleaved then you'd put it all in one vertex buffer. (You can also have vertex data partially interleaved and partially not. For instance, all the positions could be in one buffer, and all the other attributes - normals, UVs, etc. - interleaved in another buffer.) ...


6

Do they even serve any purpose at all? Yes for the user and developer of the shader, semantics conveys information about the intended use of a parameter. So you will know that POSITION is intended to be used as vertex position, NORMAL as vertex normal etc. Think of this as in-code documentation (not strictly the same though). Do semantics carry any ...


6

Not exactly: texture arrays are declared in HLSL as Texture2DArray for Texture2D and not as an array of texture, so it is quite different. They are almost acting as a 3D texture, where the z is a slice of the 2D Texture (in terms of uv, it is the w dimension). The difference with 3D texture is that they are not supporting trilinear interpolation between the ...


6

The key step that you're missing is the implicit slot assignment that occurs when you compile a shader. When you compile an HLSL shader that contains a bindable object (be it a Texture2D, RWStructuredBuffer, or cbuffer), each object must be assigned a slot number. This corresponds to the UINT StartSlot parameter to e.g. VSSetConstantBuffers. You can ...


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