33

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


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


11

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

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


8

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

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

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


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

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

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


6

VSSetConstantBuffers stands for VertexShaderSetConstantBuffers. Hence you also got PSSetConstantBuffers for the pixel shader.


6

It might help if you explained what you are doing with that texture exactly... In general, there are lots of good performance reasons why you can't easily access texture data in Direct3D resources from the CPU... You can't map D3D11_USAGE_DEFAULT textures as they are allowed to be placed into memory that is potentially inaccessible the CPU, and is therefore ...


6

I can't see anything fundamentally wrong with the shader, but here are a few things I find commonly done wrong with deferred shading that you might be doing. 1: Drawing full screen lights. The beauty of deferred shading is that you can pack your lights into geometry so that you only need to consider a part of the screen when drawing them (Like a cube with 2 ...


5

If you use compute shaders, or a GPU compute API like CUDA or OpenCL, then you don't need any of the graphics pipeline shaders. Depending on your application, GPU compute may be a better fit for you, e.g. if what you're doing has nothing to do with rasterizing triangles. Compute allows you to simply launch a large block of GPU "threads" running in parallel,...


5

The depth buffer is not linear. More bits of precision are available closer to the camera and so changes in depth close up end up being very tiny changes that don't convert to color differences you could actually see. Dividing by w linearizes the depth buffer such that small changes in depth result in visible changes in color. http://www.gamedev.net/topic/...


5

Applying two normal maps is not that bad. Many games apply multiple normal maps already because they're blending between texture layers (e.g. for terrain), so having a normal map representing the larger displacements and another normal map for fine details is pretty reasonable. Check out Blending in Detail by Colin Barré-Brisebois and Stephen Hill for a ...


5

There are no "DirectX" project templates for Win32 desktop applications. You just create a Win32 application and then use Direct3D 11. If you'd like a Direct3D 11 tutorial for Win32 desktop, I have one on MSDN Code Gallery. UPDATE Alternatively, you can install this extension if you move to the VS 2013 Community edition (or VS 2013 Pro+) Direct3D Win32 ...


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