ATI's treasure chest

xiaoxiao2021-03-06  63

ATI's treasure chest

V0.1

Liker

This is an open source Demo of ATI, showing some of the features of D3D8.1. This article is mainly what I read when I read the code. Because I still an initiator, if I have any understanding of the wrong place, I would like to ask the boss to help. Demo and source code can be found at http://www.ati.com/developer/treasurechest.html.

Process frame

It is the D3D81Framework we are very familiar.

While (1)

{

Render3denvironment ()

{

Framemove ()

{

Rendersceneintocubemap ()

{

For (6)

{

Renderscene (REFLECUBEMAP)

Renderscene (DiffuseCubemap)

}

}

}

Render ()

{

Renderscene

Normal

)

}

}

}

Scene organization

Object is mainly divided into two categories, one is stationary equivalent to the environment, including wall floor door and window and box; the other is the activity of the activity (treasure ^ _ ^) in the box. The box is composed of several parts, and the metal portion can be reflective, the wood part is not. Need to say this configuration (ObjectManagement.cpp_15):

Typedef struct _buttonmode

{

INT X;

Int Y;

DWORD OBJECT;

DWORD OBJECTEFFECT;

Char * ObjectTechnique;

DWORD WOODEFFECT;

Char * Woodtechnique;

DWORD METALEFFECT;

Char * Metaltechnique;

DWORD Keepeffect;

CHAR * Keeptechnique;

} Buttonmode;

The first two is the Button coordinates, followed by the active objects, wood, metal, and Effect File and Technique Name used in the surrounding environment, respectively. Some demonstrations have no active objects. Each of these four items may have multiple Effect File, and there are multiple Techniques in each Effect File.

About Cubemap

When you need the environment RENDER to CUBEMAP, you need to put the Camera on the needs of the environment that needs to be photographed. The code is as follows, when only Chest in the scene, its center of gravity is 0.

2.5F

, 0; other situations need to find the gravity of the live animal, this time Cubemap is around the active object, so the wrong reflection will be seen on the check.

ShaderDemo.cpp_323

IF (M_PDisPlayObject [0])

Camerapos = m_pdisplayObject [0] -> getWorldCenterofGravity ();

Else

Camerapos = D3DXVECTOR3 (0,

2.5F

, 0);

MatviewDir._41 = -camerapos.x; matviewdir._42 = -camerapos.y; matviewdir._43 = -camerapos.z;

POFMESH.CPP_407

m_centroid = (m_maxpos m_minpos) *. 5;

Normalizer

Normalizer is a cubemap that passes the vector of Normalize with VS to ps (or ordinary Pixel pipe), and the color value of Sample is Normalize's result, and it is CLAMP to 0 ~ 1, you can do it directly. DOT3. Of course, I have to do terrorist precomputers. Save bandwidth OR save instructions

The compact_buffer vertex format is used inside TreasureChest. In order to save bandwidth, the normal format of 4 Byte is compressed (note flip ...), and only two of the three Basis of the tangent space is saved. Then solve compression in VS while crossing another Basis. Which of the two should save which part depends on different hardware.

Pervertex & perpixel cubemap

We are familiar with Pervertex's Cubemap, and we are also very familiar with Perpixel's light. It is very similar to the light. The PERPEL's Cubemap also uses few vertices to achieve uneven effect, this time it is reflection.

(Very smooth metal)

(Metal with patter)

In fact, there are many places to introduce Perpixel Cubemap, unlike Perpixel Lighting, this time seems to be in PS.

Ps1.1 ~ 1.3 uses TEXM3X3VSPEC this fierce instruction to calculate the reflected light. Say it is fierce because it really makes too much calculation. In 1.4, it returned to the routine of DP3, MUL and ADD. In general, we need to transform the Basis of the world space to the tangent coordinate [1] in VS, so they form a matrix from the tangential space to the world space. After we saved the Vertex to Eye vector of the world space in the W component of the three BASIS (TEXM3X3VSPEC required), then in the PS, the normal map from Normal Map is converted to the world coordinate, and then calculate the reflection with the line of sight. vector. This will have the effect of reflecting from the uneven surface.

About Perpixel Cubemap, Refer to Bump Refraction in NveffectsBrowser.

More precise Cube addressing

Cube is addressed by a world space, but we calculate the reflection vector from Vertex, pointing to the place where we want sampling. When sampling, it is shifted to the center of CUBE, which is likely to point to different sampling points.

So we let the reflection vector plus a vector from the center pointing to the vertex direction to calculate the precise direction. This direction vector is required to meet a certain length to meet the requirements.

When Perpixel passed the world coordinates to the PS, you can follow the VS after interpolation.

There is a detailed introduction to Shaderx. The electronic version of this book is everywhere, I really regret bought paper, 555555555

Diffuse Cube Map

Saved on Cubemap is a superposition of multiple light. It is the advantage of how many light sources are available, as long as one pass, and can dynamically modify the number of light sources. When superimposed, you need this:

ZENABLE = FALSE;

Alphablendenable = true;

Srcblend = one;

Destblend = one;

Bump Specular

Base * (Ambient N.L)) (Gloss * Highlight)

Gloss is saved in the base texture of alpha, multiplying the true Specular with the 64th part of N.H.

to be continued…

转载请注明原文地址:https://www.9cbs.com/read-82447.html

New Post(0)