background preloader

DirectX

Facebook Twitter

Effects (Direct3D 11) The first step is to organize the state you want to control in an effect.

Effects (Direct3D 11)

This includes shader state (vertex, hull, domain, geometry, pixel and compute shaders), texture and sampler state used by the shaders, and other non-programmable pipeline state. You can create an effect in memory as a text string, but typically, the size gets large enough that it is handy to store effect state in an effect file (a text file that ends in a .fx extension). To use an effect, you must compile it (to check HLSL syntax as well as effect framework syntax), initialize effect state through API calls, and modify your render loop to call the rendering APIs. An effect encapsulates all of the render state required by a particular effect into a single rendering function called a technique. A pass is a sub-set of a technique, that contains render state.

A set of techniques can be grouped in a group (which uses the syntax "fxgroup"). In This Section Related topics. XNA Tutorial > Pixel shader. Up to this point, we have a vertex buffer, filled with only 3 vertices defining a single triangle.

XNA Tutorial > Pixel shader

We also have the metadata: the VertexDeclaration, which describes what kind of data is contained in the vertex data, together with the offset to that kind of data. We also have a very simple vertex shader. From our vertex stream, it extracts only the position data. For each vertex, this 3D position is transformed to 2D screen coordinates, and passed on to the pixel shader. To perform this transformation, we multiply each vertex with the matrix which is the combination of the View and Projection matrix, which is at this point not yet being specified by our XNA code.

In our XNA app, it is time to load our own effect file we created, and set the transformation matrix. Effect = Content.Load<Effect> ("OurHLSLfile"); We’re ready to move on to the Draw method. ID3DXEffect interface. Direct3D Effects Files. One big problem programming games for the PC Platform is that the specification of the platform varies widely.

Direct3D Effects Files

Users of your game may have really old graphic cards or the very latest card with all the bells and whistles. Traditionally when a Direct3D game starts up it tests the machine to see what is available, e.g. does this machines' graphic card support pixel shaders 2.0? The rendering of primitives is then done with the best method for that card. This can be really clumsy and create a lot of spaghetti code and data. Effect files allow the programmer or artists to specify different techniques dependant on the capabilities of the platform. Another issue that is growing in games development is the huge amount of art assets required. Effect files can contain different rendering techniques that can be chosen based on the hardware available as well as HLSL code to define rendering. DirectX Tutorial.com - Simple Modeling. [DX11] Sprite/Text Rendering - DirectX and XNA. Be careful with your matrices...by default the shaders will expect column-major matrices in constant buffers.

[DX11] Sprite/Text Rendering - DirectX and XNA

So you need to either transpose before setting them into the constant buffer, or transpose in the shader, or mark them as "row_major" in the constant buffer declaration, or compile your shaders with D3D10_SHADER_PACK_MATRIX_ROW_MAJOR. This was the problem with the verts, transposing the matrix now yields 'correct' coordinates, however, nothing seems to be drawn(even forcing the PS to output a static color doesn't show anything), the 3d stuff in the background seems to render ok.

I've check all my blend/raster/sampler states and made them match those from your depth sprites example(except with src/inv src alpha blending), so is there anything else that could cause the quad to not get drawn? EDIT: GOT IT! Seems I missed this: pRasterDesc.DepthClipEnable = TRUE; Code Optimization. This topic describes optimization considerations and strategies with the DirectXMath Library.

Code Optimization

Use accessors sparingly Vector-based operations use the SIMD instruction sets and these make use of special registers. Accessing individual components requires moving from the SIMD registers to the scalar ones and back again. Use correct compilation settings For Windows x86 targets, enable /arch:SSE2. By default, compilation against the DirectXMath Library for Window x86 targets is done with _XM_SSE_INTRINSICS_ defined. Code outside of DirectXMath is handled using compiler defaults. We highly recommend that you always use the latest available version of the compiler. Use Est functions when appropriate Many functions have an equivalent estimation function ending in Est.

Use Aligned Data Types and Operations The SIMD instruction sets on versions of windows supporting SSE2 typically have aligned and unaligned versions of memory operations. Properly Align Allocations Avoid Operator Overloads When Possible.