3D Terrain Multilayer Texture Mixed Shadow Rendering Method Terrain Multilayer Texture Mixed Closed Shadow Rendering Method
The terrain is very large, there is a large number of vertices, so it often takes up a lot of memory space, so you should find a way to save space on the terrain map. A lot of games, although the texture of different locations seems to be different, the surface texture is very rich, but in fact, the original map is very small, and the reason why the surface texture changes the multi-end visual effect because it is used. Alpha mixed and shaded to produce an illusion. 2.5D online game "Miracle" (MU), all 3D engine Torque (multi-person network FPS game "tribes 2", this engine), the full 3D ski game "SuPreme Snowboarding", of. (See the screenshot at the end of the article) I envisioned a solution. You need to use the Diffuse colors of the vertex, 3 Texturestage. In fact, the so-called multi-layer texture, when it is on a triangle, many games only use 2 layer textures to do alpha mix (because maybe the player's graphics card only supports 2 layers of multitExture mix), then a layer of light texture. The top 2 layer texture should be Alpha mix, where is Alpha from? If you use the alpha map, you will inevitably add a layer of TextureStage, and I choose Diffuse using the vertex to save this layer of Texturestage: Provide the ALPHA values provided by the ALPHA value for the first two Texturestage. The following is provided in the D3D: // TextureStage 0pd3dDevice-> SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); pd3dDevice-> SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE); pd3dDevice-> SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); // TextureStage 1pd3dDevice-> SetTextureStageState (1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA); pd3dDevice-> SetTextureStageState (1, D3DTSS_COLORARG1, D3DTA_TEXTURE); pd3dDevice-> SetTextureStageState (1, D3DTSS_COLORARG2, D3DTA_CURRENT); pd3dDevice-> SetTextureStageState (1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); in TextureStage 0, no doing anything, leave the first layer texture to the Texturestage 1; in Texturestage 1, Colorop uses D3DTOP_BLENDDIFFUSEALPHA, which is the use of Alpha values from the vertices Diffuse as a mixed factor mixed Layer 2 texture and Texturestage 0 original seal Layer 1 texture that is not moved. The hybrid formula is as follows (from the DX help document): Result = arg1 * alpha arg2 * (1 - alpha) arg1 is from the color of the Layer 2 texture, arg2 is the color of the first layer texture from Texturestage 0. . Further, the alpha value here is obtained after the D3D interpolation operation, so the mixing effect is very smooth.
Do you not believe that 2 layer texture is mixed to get rich surface visual effects? You should believe that although Arg1 and Arg2 are always constant from 2 maps, the two are constants, but the alpha value is variable, but the alpha value is different. Will produce different Result. Suppose the map corresponding to Arg1 is a map of a grass, and the map corresponding to Arg2 is a sand map, in a topographic area, only uses these two maps, but due to the different ALPHA values of the vertices, You will see the final rendered terrain area, the distribution of the grass is not uniform, and some places have more likes, and some places have more sand. This effect looks natural. Of course, you don't limit your use of more surface textures on a terrain scene, but for a triangle, 2 textures are enough, other textures are used on other triangles, which can produce a richer landform. For example, you want another topical area to be snow and rock style, then use 1 snow map in that area, 1 rock map. Now there are 4 posts in this level, but the same triangle still uses only 2 posts (this is the hardware limit !!). Now the shadow is now. The ALPHA channel of the vertex Diffuse has been used in front, and now his RGB has three components to be used. In D3D set as follows: // TextureStage 2pd3dDevice-> SetTextureStageState (2, D3DTSS_COLOROP, D3DTOP_MODULATE); pd3dDevice-> SetTextureStageState (2, D3DTSS_COLORARG1, D3DTA_DIFFUSE); pd3dDevice-> SetTextureStageState (2, D3DTSS_COLORARG2, D3DTA_CURRENT); pd3dDevice-> SetTextureStageState ( 2, D3DTSS_ALPHAOP, D3DTOP_DISABLE; this is the third Texturestage, colorop is multiplied, and Arg1 is set to diffuse, which is from the D3D interpolated vertex Diffuse color, arg2 is the result of Texturestage 1. The mixing formula is as follows: Result = arg1 * Arg2 color is RGB three bytes (or other color format), but D3D will be removed into separate three RGB channel values (0-1 floating point). The multiplication operation can be attached to the color light and shadow effect. One problem is that people choose to use the light map to improve the accuracy of the light and shadow, because the vertex light acts only on the vertex, although the rendering API will interpolation between the vertices, but this is only very intensive at the vertices. There is a very precise light, and if the fixed point is sparse, it can't even produce the correct illumination effect. Here, the vertex Diffuse will not have a satisfactory illumination effect? I thought about using a whole photo on the entire top, but I suddenly remembered that this is the same problem and precision with HEIGHTMAP-based terrain technology. Using HeightMap, in order to reduce the game volume, this HeightMap is impossible, it is impossible to only correspond to one vertex, but a plurality of vertices are mapped to the same height. A entire light map is also facing the same problem, maybe a plurality of vertices use the same pixel on the light map? If the two vertices are used by the same pixels on the light map, the space between the vertices is definitely used to use this pixel, which will not increase accuracy.
Increase the size of the light map? That is to choose 512 * 512, or 1024 * 1024? In fact, the vertices of the LOD terrain are always dense. At least in the area close to the camera, it is often intensive than the vertices of the indoor building. Although it has not been intensive to create a satisfactory effect, it is sufficient to use the shadow effect generated by the vertex light to simulate terrain due to high and low fluctuation. Moreover, the industry generally believes that the accuracy of terrain rendering is lower than the indoor rendering of a grade (new game Farcry is an exception). What is even better, the vertex light information can be stored in the high graph, we change the height point from a unsigned char to a multiberic data structure: struct heightpoint {unsigned char guide; // Used to calculate the fixed y coordinate value ALPHA for rendering the terrain high from the unsigned char alpha; // fixed point Diffuse, used for multi-layer texture mixing unsigned char red; // vertex Diffuse RED, used to illuminate unsigned char green ;; / / vertex Diffuse Green, For illumination unsigned char blue; // vertex Diffuse's Blue for illumination}; such a high graph information not only contains height information, but also a multi-layer texture mixing information, light information. When dynamically created terrain, it is very convenient to obtain a DiffUse value corresponding to the vertex while reading height data. Below is the MFCTex program verification theory with DX. The 3 TextureStage is exactly the use of the settings mentioned above. Figure 1ENV2.BMP is a map of brick wall, caust11.tga is a water-surfaceed texture, ENV3.BMP is not used. Diffuse colors are 0x77ff0000, pure red, but the alpha value is 119. Stage0 Reserves the image data of Env2.BMP to Stage1. STAGE1 COLOROP uses D3DTOP_BLENDDIFFUSEALPHA method, with Diffuse's alpha value (119 => 0.53) for mixing factor mixing caust11.tga and env2.bmp, formulas: Resultofstage1 = caust11.tga * 0.53 env2.bmp * (1 - 0.53 ), The resulting visual result is that we can see the brick wall and see the water ripples, they are mixed by a translucent mix. STAGE2 multiplied by multiplying, multiplying Diffuse's RGB three-point quantity with Resultofstage1 (Current is Resultofstage1), because Diffuse's RGB is FF0000 pure red, completely without Green and Blue components, so this time it is visual The result is a red biased throughout the wall. In this way, we have created a corrugation that was cast in the wall, and the entire wall was illuminated by a red light. Let's take a look at the Torque engine, "extreme ski" topographic map rendering effect. The first is TORQUE. The texture files used by the Torque engine Demo are not packaged, so I can easily find these articles, draw them with Photoshop to mark them, and to the game how they are mixed, and how to stick to the ground. This demo only uses 3 floor textures: 1 grass.jpg, 1 Sand.jpg, 1 Patchy.jpg.
Each texture, I first use the red thick line to tell its 4 edges, and then write its file name in the upper left corner and the lower right corner, I also write to them to Chinese translation, grass.jpg is "Grass", Sand. JPG is "sand", patchy.jpg is "sparse grass". Looking at the screenshot: Figure 2 Each topographic texture is 256 * 256, from the air this point of view, each texture is mapped to a quite large square area on the topography, so when the lens is close to the ground, it will become very Blur, but Torque will put the detail texture at this time (see the screenshot behind), a picture file called Detail1.png (still only one, but the effect is very good), this is another technology, here is not a table . In the figure, all yellow areas come from Sand.jpg. We look at the square area of "sparse grass" on that on the left. This area is used by patchy.jpg and Sand.jpg two textures, "ground" is just in the mixed boundary, so it is blurred. Is the mixture not a vertex Diffuse alpha? So in this area, there must be more vertices, no problem, Torque uses a quad tree to create a terrain. This square area is subdivided into a smaller square area, and is not a balanced (LOD technology), so there is enough The vertex, while it seems that the mixed boundary is twisted. This DEMO can switch to a wireframe rendering mode, I have observed the distribution of the vertices, indeed consistent with the distribution of Alpha. A screenshot: Figure 3 Seeing this screenshot, the existence of shadows does play a role in the visual effect. Look at the square area on the left, almost all the sand, but there is a shadow, the effect is much better. You may think that its shadow is very meticulous, but don't forget this is a full 3D FPS game, I am on a very high air bullish. Another game "extreme ski", this is a commercial game made in a country in Europe. Although it is a commercial game, its texture file has not been packaged, naked JPG, TGA, so I replace these textures to only one color picture, then outline the four edges of the picture, and play the file name. Because it is a ski game, the most common color in the scene is white, so only the same texture is used in a wide range of textures. Figure 4 Of course, you have to add a shadow, or you will really burn the eyes of the player. With shadows, the effect is better. Plus colored light shadows, it is quite fascinated. Look at: Figure 5 The mountains and highways in the game require other textures to mix. Figure 6 looks at the shadow of Figure 6, especially on the left, there is a more obvious step, the rectangle on the right, but it should be the shadow of the tree, but it is very scattered, it is very inconsistent, and the effect of the vertex is very similar, maybe Scene Editor stores the calculated shadow information to the Diffuse of the vertex. This game's snow texture is only 2, and the other has a smaller frequency. Attached: Torque details texture Figure 7
<< The picture is uploaded in the RAR file. >>