All phones based on Windows Phone, according to the requirements of Microsoft, have hardware graphics acceleration that supports 3D rendering. XNA 4.0 includes 5 basic shader effects for 3D graphics and several options for their additional configuration. This is the main palette for use in 3D games for the phone. You can download an example to get acquainted with how they work. This article provides an overview of all five shaders, and they are illustrated with short videos that give an insight into their basic visual capabilities. As already mentioned, in Windows Phone 7 XNA 4.0 SDK 5 3D shaders are implemented in the respective classes.
BasicEffect
SkinnedEffect
EnvironmentMapEffect
DualTextureEffect
AlphaTestEffect
Despite the fact that in Windows Phone 7 there is an infrastructure of shaders, the ability to program them directly in the HLSL language is not yet available. Nevertheless, the source codes of these shaders can be found in the examples section of the App Hub. Let's look at what each of these shaders are capable of.
BasicEffect
The first is the Basic effect. This class was already in version XNA 1.0. It supports zero to three light sources, is based on the standard Blinn-Phong model. Optionally, an additional texture map, smoke, and color data for vertices are also supported. The inclusion of certain options can significantly affect the performance of graphics output.
DualTextureEffect
A great choice for 3D graphics on the phone. This method imposes two textures on 3D objects, and the coordinates of the second texture can be different from the first, rotated relative to each other, etc. We can say that this is a secret weapon in the graphics for smartphones. With all the simplicity, this effect is very fast, and allows the use of such techniques as light maps and detailed textures. The two textures are mixed using the Modulate2X formula. Output.rgb = Texture1.rgb * Texture2.rgb * 2; Output.alpha = Texture1.alpha * Texture2.alpha; The easiest way to understand this operation is that the first texture determines the main color of the object, which can then be modified with a second texture. If the second texture is gray at 50%, then the result will be the original color of the first texture. If the second texture is 70% gray, the result will be brighter than the original texture.
')
Alpha Test Effect
This is the real cheating in the world of 3D graphics. The alpha testing algorithm is that the testing function with boundary conditions (none, greater than, less than, equal, less than or equal, greater than or equal) is used when outputting a pixel and depends on the alpha level. Any fragment (a pixel that did not pass the full cycle of shading) that does not satisfy the conditions of the test is simply not processed. This allows, for example, to draw one complex 3D object into memory, and then copy it to the screen as 2D with scaling, using the information in the alpha channel to process transparent areas. Such a method can be useful for displaying a set of similar objects. In order for them not to look like copying each other's movement, you can render 3-5 objects with different phases of movement and then copy them in an asymmetrical order. This will create the illusion of the uniqueness of the movement of each such object, but it will significantly save resources.
Skinning effect
This effect is intended for skeletal animation of objects. Your game code controls only the “bones” of the object, greatly facilitating work with the vertices of the 3D model. Vertices will move in accordance with the position of the "bones", the coordinates of which will be calculated by the GPU. Windows Phone 7 supports up to 72 "bones" which, in principle, is enough for very complex animation.
Environment Map Effect
The final effect in our list, which allows you to display 3D objects in the most colorful way, imitating the brilliance, reflections and highlights. The basis for this effect is the consideration of a cubic map, or in other words a sweep of a cube texture consisting of 6 surfaces. A 3D object is located in the center of such a cube and reflects those textures that surround it. This effect is almost the same as BasicEffect and additionally takes as its parameters the values of the three coefficients affecting how the object will be displayed.
Windows Phone 7 Shader Capability Chart
In order to more fully understand what shaders to use in certain cases, as well as to compare their capabilities, you can use this table:
What's next
If you are interested in 3D graphics programming for Windows Phone 7, then you need to download the development tools and the latest version of Windows Phone SDK 7.1
Ivan Andreev iandreev some time ago prepared a series of articles on 3D programming for Windows Phone. Below are links to materials.