Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Microsoft XNA Game Studio Creator’s Guide- P6:The release of the XNA platform and specifically the ability for anyone to write Xbox 360 console games was truly a major progression in the game-programming world. Before XNA, it was simply too complicated and costly for a student, software hobbyist, or independent game developer to gain access to a decent development kit for a major console platform. | 128 MICROSOFT XNA GAME STUDIO CREATOR S GUIDE Texture coloring It is possible to color your image textures at run time. This technique might be handy for a number of instances maybe you need your texture to be darker and you can t wait for the artist to fix it so you decide to shade it in your code. Maybe you want to create a stone pattern you could use the same image to draw all stones but alternate the shade to create more contrast on the surface. The Texture.fx shader is already able to apply colors which are stored in the vertices to any textured item. If a non-white color is stored in the vertices the image in the texture will be shaded by this color. To demonstrate how this works it helps to examine the vertex shader and pixel shader. The vertex shader input receives the color stored in the vertices. The user-defined struct that stores the vertex shader output stores this color information. The vertex shader output by design serves as the input for the pixel shader. This vertex shader code receives the color from the vertices that are set in your C code and passes it to the pixel shader void VertexShader in VSinput IN out VStoPS OUT OUT.position mul IN.position wvpMatrix transform object orient it in viewer OUT.color IN.color send color to p.s. OUT.uv IN.uv send uv s to p.s. The pixel shader can only return colored pixels as output. On the first line of the shader the texture is applied to each vertex using the tex2D function which uses the textureSampler filter and UV coordinates as input parameters. The pixel shader uses linear interpolation to shade and texture the area between the vertices. On the second line this optional instruction is added which multiplies the colored pixel by the color that is stored in the vertices. This modification in effect applies a color to the image texture void PixelShader in vsOutput IN out psOutput OUT apply texture to vertices using textureSampler filter OUT.color tex2D textureSampler IN.uv apply color from v.s. - p.s. .