Terrain reading note: Chapter 3

xiaoxiao2021-03-06  15

Chapter 3. The High-Level Shader Language

As the title, this chapter is all HLSL. Liker said Shader often calls, do not write with high-level Dongdong, use Assembly. I also think it is like this. However, since Snook wrote this chapter, I still take a look, I will be a science.

The HLSL Shader Format

Like HLSL and C, there are three parts: 1) Variable Declaration 2) Type Definition 3) Function

Variable & Data Types

The data type supported by HLSL: 1) Scalar: Bool, Int, Half, Float, Double2). Vector: Vector (consisting of 4 FLOAT), Vector (NUM member, all values ​​are T) Scalar) 3) Object: String, Pixelshader, VertexShader, Sampler, Texture4) Vector Typedefs: Bool #, int # 5) Matrix Typedefs: Bool # x #, int # x # x #, Float # x #, Half # x #, double # x #

* Note: 1. # Represents a number of 0-4 2. Not all data types are supported by hardware, if not supported, the type of type supported will be simulated. For example: INT, HALF or DOUBLE use float to simulate if not hardware support. If you exceed the range of float, you will have trouble. So all variables in Shader are best used in SHAAT unless the range is determined.

Variables like C, can be modified with extern, static, const, volatile. Also HLSL also has new modified keywords:

1) Uniform: Global variables and input parameters can be defined as uniform, indicating that the value does not change during the SHADER execution 2) Shared: When a variable is used by multiple shader, use Shared to modify, when this update variable All shader will be updated.

All variables in HLSL are all values, and pointers or reference are not allowed.

Semantic (semantic) is used to represent the use of variables. In addition to the semantics supported by HLSL, you can define semantics themselves.

Expressions & Intrinsic functions

HLSL supports all mathematical operations, logical operations, and comparative operations of C / C . Expression in HLSL can be written into a form of C / C .

HLSL is unlike C, there is a luxurious Math function library, but it defines the fixed function to complete the features required for Shader. In addition to functions such as simple as MUL, it is better to write a function of refraction light after refraction of transparent media, which is very suitable as a function of refract, which is very suitable for writing shader.

Working with Texture & Samplers

The sampler is used to display and filter quality. Like fixed-function pipeline, Sampler's State can also be set in the PS.

HLSL supports Sampler1D, Sampler2D, Sampler3d, SamplerCube 4 sampler, but can be declared simply by Sampler. The compiler will automatically select one.

I understand the PS is like this: the program is supplied to a coordinate of the PS, then the PS returns the color of the Pixel. The simplest is the post material. After each sample, the PS returns a FLOAT4 VECTOR that contains the color -RGBA of the Pixel. Procedural Texture Shaders

Ps can not only be used to render Target, but also can be used to generate Texture. Then then use this texture in later procedures.

Considances for Legacy Hardware

The development of technology and the update of hardware seem to have a total contradiction. While enjoying new technologies, don't forget that many users are still using the mainstream graphics card before. So this is to take into account this situation.

If a technical hardware is not supported, but if you can simulate, if the app is running slowly. However, if the software simulation is not working (such as PS), then ... Money exchange equipment.

If the technical hardware used in HLSL does not support, Error Codes will be generated. If an error occurs, this error Codes will be written to a D3DXBuffer when you compile. Check it.

In addition, under the / bin / dxutils under the SDK directory, there is a FXC.exe, which is the compiler of .fx files. This stuff can compile FX into an OBJ file. However, there is an advantage that when you add / fc parameters, it will output the FX corresponding asMbly output. This is more intuitive to see which things are not supported by the old graphics card.

HLSL Functions forin Effect Files

If you want to use PS and VS in Technique, you only need to declare the VertexShader object or the Pixelshader object. such as:

Technique SimpleShader {Pass P0 {// Shaders VertexShader = compile vs_1_1 vs (); pixelshader = compile ps_1_1 ps ();}}

Of course, HLSL can not only be written separately in Technique, not only by external functions.

In addition, there is a tool called EffectedIit in DirectX SDK to preview the effect of Shader.

The 点 点 水 水 水 水 水 水 研究 研究 研究 研究 研究 了 了 了 了 了 了 看 了 了 了 了 了 了 了 了 了 了 了. 了... 了...... 了....... 了 了 了 了 了 了 了 了

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

New Post(0)