28

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


21

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


18

The ID3D11Buffer references an actual chunk of memory that holds your data, whether it's a vertex buffer, constant buffer, or whatever. Constant buffers work the same way as vertex buffers and other kinds of buffers. Namely, the data in them isn't accessed by the GPU until it actually renders the frame, so the buffer has to remain valid until the GPU is ...


15

I think the main optimization you can make, is based on the fact that not every cube will actually need all 24 vertices. In fact, the only cubes that need 24 vertices are the ones that are floating in midair, which is probably a rare occurrence. In general, only generate quads for the faces that are in contact with air. This means that if two cubes are ...


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


15

While technically true, the statement in that tutorial is phrased somewhat misleadingly and in a bit of an alarmist fashion. Generally speaking you do not need to worry about this. Anyway, what does it mean that it'll draw polygons within that range? Model vertices in the graphics pipeline go through several different stages as they pass through the ...


14

When multiple render targets are bound, they can each be written to individually by the pixel shader -- it isn't (necessarily) the case that all render targets will get the same image. You could write only the red component into one output, only the blue into another, et cetera. This is used when implementing deferred rendering for example: position, normal,...


14

When one talks about OpenGL and D3D "features," one could be referring to either: the feature sets supported by hardware that the graphics API exposes, or the feature sets of the API itself that don't really relate to the hardware. For example, a programmable tessellation pipeline is something the hardware generally has to support (let's ignore, for the ...


11

You should usually prefer to use the D3D11 API, because it introduced downlevel feature level support that allows you to target 9, 10 or 11 level features using the same (D3D11) API. This means cleaner, more compact code so long as you don't have to support XP (and thus need to use the actual D3D9 API as well). If you choose to require D3D11-level features, ...


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 effect functionality was refactored. It's fundamentally the same set of operations, you just have more control over them -- similar to how the D3D10+ interface redesign does mostly the same stuff as the 9 API, but affords you a more direct model of the hardware or driver to work with. The cost of this change to you is more verbosity in your code; more ...


10

In the D3D11 parlance A buffer is a type of resource that contains data in various formats. Buffers are used to create textures (a buffer of texel data), meshes (buffers of vertex data with corresponding buffers of index data) and so on. A view an interpretation of some resource or buffer. Buffers are stored in generalized memory formats to facilitate their ...


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


9

need to handle rendering large astral bodies from extreme distances Consider the scale of the Solar System. 8 planets, and we're currently on one. Our closest neighboring planet, Venus, is almost the same size as Earth. Yet, it is so far away from the Earth that it appears as nothing more than just another star in the sky. Jupiter is the largest planet in ...


9

Actually that "while loop" that you wrote there is the source of your problem. GetMessage puts your application to sleep until a message arrives. This is good for GUI applications but obviously is not good for games. The right way of doing the game loop is using PeekMessage instead so that your application is not put to sleep and can just keep spinning. ...


9

If you only need per-face normals, and if your texcoords for a face are strictly 0/0, 0/1, 1/0, 1/1 (or similar to suit your layout) then you can construct a cube with 8 verts and either 30 (strip with restart) or 36 (list) indexes. Fetch the normals and texcoords using a constant array lookup based on SV_VertexID in your vertex shader. Doing this means ...


8

Misunderstood the question, see the comments. You basically have three choices: Throw an exception Return an error code and use an out parameter to return the actual value Call an error callback Exceptions: Very simple to implement, however they might incure a huge performance and/or memory impact, even during normal execution, depending on the compiler. ...


8

I'm pretty certain this has to do with Texture addressing. If you could post the sampler state part of your shader then I'd could rule that out. Also is this a texture atlas (many used images stored in 1 texture)? Texture addressing handles regions outside of the 0.0 to 1.0 range. When filtering other than point is applied the rendered texture will use ...


8

You don't choose which render target to present. The IDXGISwapChain object owns the back buffer (the render target that gets presented); it's automatically created when the swap chain is set up. To draw to the back buffer, you first get a reference to it as a texture by calling IDXGISwapChain::GetBuffer; then you set up a RenderTargetView from that. In ...


8

D3D11 does not have a "device lost" concept, at least not one like D3D9 had (with it's related "on-lost" and "on-reset" management). DXGI, which you'll use with D3D10+, has error codes for the device being physically removed and one for a reset due to a bad command, but these require very different handling.


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

A given shader model exposes a particular set of registers to HLSL; these registers are underlying hardware registers on the GPU, like CPU registers, but have more refined scopes (for example, there are registers dedicated to holding samplers). Registers are where all your data is stored during the execution of your shader (with the exception of data, like ...


8

Because the alternative is worse. There's a set-constant-buffer function for each major shader type because it is often desirable to have a completely different set of constants for each (and also, because one does not necessarily utilize every type of shader in all scenarios). It's usually the case that each stage of the shader pipeline does a drastically ...


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

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


8

Out of curiosity (and peace of the mind...) I wondered how DirectX decides which attribute from a struct corresponds to the right variable inside an HLSL cbuffer-register(x) (apart from the order/type they are declared with). Purely through memory layout. You give D3D a pointer to a chunk of memory which you claim to be organized in a certain fashion (...


7

Taken from Wikipedia, too: there aren't many differences. Strictly speaking, OpenGL is usually slightly behind Direct3D in terms of features, because the standardisation takes time. However, many of these features are available as OpenGL vendor-specific extensions first, then in the standard itself after some time. Compute shaders are available in GLSL ...


7

This is a tricky question because you don't have complete control over whether a vertex buffer is stored in VRAM or main RAM. The driver makes that decision for you based on the usage and CPU access flags specified when you create the vertex buffer. Generally speaking, buffers with default and immutable usage will be stored in VRAM; those with staging ...


7

When rendering with multisampled anti-aliasing, a coverage value is computed for each fragment; this coverage value is based on the fraction of the pixel that would be covered by the fragment based on the triangle that created the fragment. The net result is that the edges of the triangle are anti-aliased. Because the coverage is based ultimately on what the ...


7

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


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