Chapter 3 introduces pixel shaders
Read this article shows that you have agreed to the statement
3.3 Using the list of pixel shaders outlines the necessary steps to create and use the pixel shader: 1. Write and compile pixel shader 2. Create an iDirect3dpixelshader9 interface to represent a pixel shader based on compiled code.
3. Use the idirect3ddevice9 :: setpixelshader method to allow this pixel shader
Of course, we must destroy it after using the top shader. These steps will be deeply invested in the following sections. 3.3.1 Write and compile pixel shaders We compile pixel shaders in the same way as compilation vertex shader. First, we must write a pixel shader program. In this book, we write our shaders with HLSL. Once the shader code is written, we can compile the shader with the D3DxCompileshaderFromFile function, as described in Section 2.2. Memolive, this function returns an ID3dxbuffer pointer that contains compiled shader code.
Note: Because we use a pixel shader, you have to remember to change the compilation target to a pixel shader target (such as: ps_2_0), not the vertex shader target (such as: vs_2_0). Compiling the target specifies through a parameter of the D3DxCompileshaderFromFile function. See Section 2.2 for details.
3.3.2 Creating a Pixel Shader Once we compile the shader code, we can get an interface pointer of iDirect3dpixelshader, which represents a pixel shader, using the following method: HRESULT Idirect3DDevice9 :: CreatePixelshader (const DWORD * PFunction, idirect3dpixelshader9 * * PPSHADER; PFUNCTION - The pointer PPShader "The compiled shader code is compiled PPShader - Returns a pointer to an iDirect3dpixelshader9 interface, for example, assumes that the variable shader is an ID3DXBuffer interface pointer containing the compiled shader code. So to get the IDirect3dpixelshader9 interface, we should write:
IDirect3dpixelshader9 * MultiteXPS = 0;
HR = device-> CreatePixelshader
(DWORD *) Shader-> getBufferPointer (),
& MULTITEXPS);
Note: Reiterates that D3DXCompileshaderFromFile is a function that can return the compiled shader code. 3.3.3 Creating a pixel shader After we get a pointer to the IDirect3dpixelshader9 interface representing our pixel shader, we can use the following method to allow it:
HRESULT IDIRECT3DDEVICE9 :: SetPixelshader
IDirect3dpixelshader9 * pshader
);
This method accepts a single parameter, through it, we pass a pointer we want to point to the pixel shader. We should write: device-> setpixelshader (MultiteXPS); demary-> setpixelshader
3.3.4 Destroying the pixel shader, like all of all Direct3D interfaces, to clear these interfaces, we must call their Release methods after use. Continue to use our pixel shader created in Section 3.3.2, we write: D3D :: Release