3D terrain Multi-Layer Texture hybrid shadow rendering method

Source: Internet
Author: User
Fixed:

I looked at the terrain of the torque engine demo and found that he had used at most three textures in a square. Three texture stages are required for the three pasters, and two stages with Alpha values are added. A total of five texture stages are required. This is too demanding for the video card. At least my video card supports only four texture stages. Therefore, multipass must be used for rendering multiple times. This article Article The method of storing Alpha information in vertex diffuse is worth considering. If an Alpha image is used, the Alpha image will always be stretched so that the natural transition between different textures on the terrain is still not allowed. Unless your terrain has a larger concept of a region, using an Alpha chart for a region may solve the problem of over-stretching the Alpha chart. Otherwise, if you only use a globally unique Alpha chart, it will be hard to get the desired effect.

One benefit of Alpha provided by fixed-point diffuse is that d3d performs interpolation, so that Alpha at a certain point will not be extended into patches, because the new value it expands will be calculated by d3d interpolation. To achieve a combination of up to three Textures like torque, two diffuse copies are required for the same terrain. You can consider using multi-stream technology to make diffuse data a separate stream.


Original

Multi-layer terrain texture hybrid shadow rendering method

Because the terrain is very large and requires a large number of vertices, it often occupies a lot of memory space, so we should try to save space on the terrain map. Although the textures of different locations seem to be different from each other in many games, the texture of the earth surface is very rich, but in fact there are very few textures actually used, the reason why the visual effects of the surface texture are changeable is that the use of alpha mixture and shadow creates an illusion. 2.5D online game "miracle" (MU), full 3D engine torque (Multiplayer Online FPS game "Tribe 2" uses this engine) all 3D skiing games, supreme snowboarding, do this. (See at the end of the article)

I have imagined a solution for this. The diffuse color of the vertex and three texturestage are required. In fact, the so-called multi-layer texture, specific to a triangle, many games only use two layers of texture for Alpha mixing (because maybe the player's video card only supports two layers of multitexture mixing ), next, we need a light texture. The first two layers of texture need to be Alpha mixed. Where does Alpha come from? If an Alpha texture is used, a layer of texturestage must be added, and I can use the diffuse of vertices to save this layer of texturestage: the Alpha value provided by the alpha channel of diffuse is used together by the first two layers of texturestage. The settings in d3d are as follows:

// Texturestage 0

Pd3ddevice-> settexturestagestate (0, d3dtss_colodrop, d3dtop_selectarg1 );

Pd3ddevice-> settexturestagestate (0, d3dtss_colorarg1, d3dta_texture );

Pd3ddevice-> settexturestagestate (0, d3dtss_alphaop, d3dtop_disable );

// Texturestage 1

Pd3ddevice-> settexturestagestate (1, d3dtss_colodrop, 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, nothing is done. Leave the first layer of texture intact to texturestage 1. In texturestage 1, colodrop uses d3dtop_blenddiffusealpha, that is to say, the Alpha value from the vertex diffuse is used as the blending factor to mix the layer 2nd texture and the layer 1st texture left intact by texturestage 0. The mixed formula is as follows (from the DX help documentation ):

Result = arg1 * Alpha + arg2 * (1-alpha)

Arg1 is the color from the 2nd layer texture, and arg2 is the color from the 1st Layer Texture left intact by texturestage 0. In addition, the Alpha value is obtained after d3d interpolation, so the mixing effect is smooth.

Do you believe that layer-2 texture mixing can produce rich visual effects on the surface? You should believe that although arg1 and arg2 are always constant from two textures, for the same point on the triangle, these two are constants, but the Alpha value is a variable, if the Alpha value is different, different results are generated.

Assume that the texture corresponding to arg1 is a lawn texture, and the texture corresponding to arg2 is a sand texture. In a terrain area, only these two textures are used, however, due to the different Alpha values of diffuse of each vertex, you will see that the final rendered terrain area shows uneven distribution of lawns, and the grass looks more like in some places, some places have more sand. This effect looks quite natural.

Of course, you are not limited to using more surface textures in a terrain scenario, but for a triangle, two textures are enough. Please use other textures on other triangles, this can generate richer landform. For example, if you want another terrain area to be in the style of snow and rock, you can use one Snow texture and one rock texture on that area. Now there are four textures in this level, but the same triangle still uses only two textures (this is a hardware limitation !!).

Shadow. We have used the alpha channel of vertex diffuse before, and now the three RGB components will also be used. Set d3d as follows:

// Texturestage 2

Pd3ddevice-> settexturestagestate (2, d3dtss_colodrop, 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 3rd texturestage, colodrop for multiplication, arg1 for diffuse, is from the vertex diffuse color after d3d interpolation, arg2 is the result of current is texturestage 1. The mixing formula is as follows:

Result = arg1 * arg2

Although the color is in RGB format, d3d splits it into three RGB channel values (floating point numbers between 0 and 1 ). The multiplication operation can be attached with color light and shade effects.

One problem is that people chose to use illumination graphs to improve the accuracy of light and shade, because vertex illumination only applies to vertices, although the rendering API performs interpolation between vertices, however, this will only produce accurate illumination when the vertex is very dense. If the fixed point is sparse, it cannot even produce the correct illumination effect. If vertices diffuse are used here, will the illumination be unsatisfactory?

I thought about using a whole illumination graph on the whole terrain, But I suddenly remembered that this is the same problem as the heightmap-based terrain generation technology. With heightmap, in order to reduce the game volume, this heightmap cannot be very large. It is impossible that each height point corresponds to only one vertex, but multiple vertices are mapped to the same height point. A whole illumination graph faces the same problem. How many vertices use the same pixel in the illumination graph? If the two vertices use the same pixel on the illumination graph, the space between the vertices must use this pixel. This will not improve the accuracy. Increase the size of the illumination chart? Is it 512*512 or 1024*1024?

In fact, the vertices of the level-4 terrain are always intensive. At least in the area close to the camera, this is often more intensive than the vertices of the interior building. Although it is not intensive enough to make the d3d spotlight produce satisfactory results, it is enough to use the vertex illumination to simulate the shadow effect of the terrain due to the ups and downs. Furthermore, the industry generally believes that the terrain rendering accuracy is lower than the indoor rendering level (the new game farcry is an exception ).

Even better, vertex illumination information can be stored in the height plane. We change the height point from an unsigned char to a multi-byte data structure:

Struct heightpoint

{

Unsigned char height; // used to calculate the Y coordinate value of a specified point, used to render terrain height fluctuations

Unsigned char Alpha; // alpha of fixed point diffuse, used for Multi-Layer Texture Mixing

Unsigned char red; // red of vertex diffuse for Illumination

Unsigned char green; // green of vertex diffuse for Illumination

Unsigned char blue; // blue of vertex diffuse for Illumination

};

In this way, the height graph information not only contains the height information, but also the Multi-Layer Texture hybrid information and illumination information. When creating a terrain dynamically, you can obtain the diffuse value corresponding to the vertex while reading the height data, which is very convenient.

Below is the mfctex that comes with DX Program Verify the theory. The three texturestage objects use the preceding setting method.



Figure 1

Env2.bmp is a wall image. caust11.tgais a watermark image, and env3.bmp is not used. The diffuse color is 0x77ff0000, which is pure red, but the Alpha value is 119.

Stage0retains the image data of env2.bmp to stage1. The colodrop of stage1 uses the d3dtop_blenddiffusealpha method and uses the Alpha value of diffuse (119 => lag, formula: resultofstage1 = caust11.tga * 0.53 + env2.bmp * (1-0.53 ), the visual result is that we can see both the brick wall and the water surface ripple, and they are semi-transparent. Stage2 is multiplied to multiply the RGB triplicate of diffuse and the RGB triplicate of resultofstage1 (current is resultofstage1). Because the RGB of diffuse is ff0000, there is no green or blue components at all, so the visual result this time is that the entire wall is red. In this way, the wall is cast on the surface of the water, and the whole wall is highlighted with red light.

Next let's take a look at the terrain Paster rendering effects of torque engine and extreme skiing.

The first is torque. The texture files used by the torque engine demo are not packaged, so I can easily find these arts and sciences and use Photoshop to mark them, then, let's see how they are mixed and mounted to the ground. This demo only uses three terrain textures: 1 grass.jpg, 1 sand.jpg, and 1 patchy.jpg. Dense is a "sparse lawn ". Let's see:



Figure 2

Each terrain texture is a 256 x image file (or only one image file, but the effect is good). This is another technology and is not shown here. In the figure, all the pornographic images are sand.jpg. We can see that the left side is a square image of the sparse grass. This image uses a mixture of patchy.jpg and sand.jpg textures. The word "Earth" is located at the mixing boundary, so it is blurred. Isn't the hybrid factor the alpha of vertex diffuse? Therefore, there must be more vertices in this area. Torque uses the quad-tree to create the terrain. This square area is subdivided into smaller square areas, and it is not balanced (with the level of detail), so there are enough vertices and it seems that the mixed boundary is distorted. This demo can be switched to the box-frame rendering mode. I have observed the distribution of those vertices, which is indeed consistent with the distribution of the Alpha mixture.

Next:



Figure 3

From this, we can see that the existence of Shadows has indeed played a role in enriching visual effects. Looking at the square area on the left, it is almost all sand, but the effect is much better if there is a shadow. You may think that the shadow is very detailed, but don't forget that this is a fully 3D FPS game, I'm in a very high air.

Another game, extreme skiing, is a commercial game made in a European country. Although it is a commercial game, its texture files are not packaged, bare JPG, TGA, So I replace these textures with only one color image, outline the four sides of the image and add the file name. Because it is a skiing game, the most common color in the scenario is white, so you can use only the same texture in a wide range.



Figure 4

Of course, you need to add a shadow. Otherwise, the player's eyes will be burned. With shadow, the effect is better. In addition, the color light and shade are quite fascinating. See the figure below:



Figure 5

The mountain and highway in the game both need other textures to mix.



Figure 6

Looking at the shadow in figure 6, especially on the left, there are obvious cascade steps. The right side is a rectangle. It should be the shadow of the tree, but it is very scattered and not right, the effect is very similar to that of vertex lighting. It may be that the scene editor stores the calculated shadow information in the diffuse of vertex.

This game has only two snow textures, and the other one appears less frequently.

Appendix: Detailed texture of Torque

 

Figure 7


<All images are in the uploaded rarfile.>

Sf_2002131212565.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.