Shader 4 is a combination of Function Terms and data structures.

Source: Internet
Author: User

Normal: normal

Normao mapping: normal texture

Lighting mapping: lightmap

Bump mapping: concave and convex textures; techniques used to simulate a rough outer surface. FX-water simple. shader is used. Simulate the wave effect.

Rim lighting: edge lighting; add? Brightness.

Base texture: basic texture.

Detail texture, detailed texture. The base texture uses the same UV, but the tiling value in material is different.

Cubemap: Cube chart

Cubemap reflection, cube chart reflection.


Lambert: lightmodel of diffuse reflection




CG functions: mathematics, ry, texture ing, skewness, and debugging.

From wenku.baidu.com/link? Url = Response

Tex2d: tex2d (sampler2d Tex, float2 S), 2D Texture query. Returns a four-element Vector Value. All texture ing functions return a four-element Vector Value.

Mul: Matrix Multiplication


Unpacknormal: The U3D standard normal decompression function; in unitycg. cginc.



The standard output structure of the surface shader customized by unity3d is: struct surfaceoutput {half3 albedo; // reflectivity half3 normal; // normal half3 emission; // self-emitting, it is used to enhance the brightness of an object and make it look as if it can emit half specular; // mirror half gloss; // glossy half Alpha; // transparent };
# Pragma surfacesurfacefunction lightmodel [optionalparams]

Surfacefunction-indicates that the CG function contains surface shader code. The format of this function should be as follows: void SURF (inputin, inout surfaceoutput O), and input is your custom structure. The input structure should include the additional required variables required by all texture coordinates (texturecoordinates) and surfacefunction.

Lightmodel-used in illumination mode. Built-in Lambert (diffuse) and blinnphong (specular ).


// Vertex shader Input
Struct appdata_base {float4 vertex: position; // vertex position float3 normal: normal; // float4 texcoord: texcoord0; // texture coordinate in the normal direction ..?};

 

// Scroll bump wavesfloat4 temp; // The four-element vector xyzw v. vertex. xzxz indicates that the four components of vertex x Z are removed to form a new vector. assign a value to temp after calculation. Temp. xyzw = v. vertex. xzxz * _ wavescale/unity_scale.w + _ waveoffset; O. bumpuv [0] = temp. XY * float2 (. 4 ,. 45); O. bumpuv [1] = temp. WZ;




From

Http://hi.baidu.com/stupidboys1027/item/e6ac3cbb4faccbd684dd799a

Semantic input, semantic output, uniform

Bind the vertex number to the vertex information based on the semantics.

Obviously, there are three different types of entry variables: semantic input number of partitions, semantic output number of partitions, and uniform input number of partitions. First, let's understand the meaning of the word "Semantics". In fact, we should call it binding semantics more accurately ), from the word binding, we can imagine that the position semantics is used to tie the vertex position vector in the pinitial environment (OpenGL. This is also the principle of output semantics. Let's answer the question we asked at the beginning: where to come, where to go. 1. Where to come from. Now let's assume that before OpenGL renders vertices, the program automatically generates such a data structure, struct vertex, which includes vertex. position, vertex. normal, vertex. color, vertex. texcoord. and so on. The information is public and can be referenced by external functions. Therefore, the value of the number of semantic input records in CG is obtained from the information. In the example, "float4 pinitial: Position" binds the pinitial variable to vertex. position through the position binding semantics, so pinitial is assigned a value. Is this the same principle as references in C ++? Note: The number of input shards is read only. 2. Where to go? If you know where to come from, you can also understand where to go (Out float3 color: color ), the number of vertices that have been modified by an out statement is the number of semantic output records. Here, we use the binding semantics of color to bind the color vector with the vertex. color value. In CG code, after a series of operations and processing, the new color of the vertex is finally obtained, and the color value is returned to the vertex attribute of OpenGL again, openGL then renders the vertex by reading this attribute. In general, the input and output of the semantic sequence number are all completed by CG itself, and the program only needs to bind it with the corresponding semantics. So much is said. We haven't said the number of partitions input by another uniform. Assume that the semantic sequence number is automatically processed by CG, then the uniform sequence number is assigned by the programmer in the program.


Http://blog.sina.com.cn/s/blog_63507a56010115gr.html




From CG Users Manual

Float2 * float2; the vector obtained by multiplying the corresponding components. It is not a cross-multiplication.

Dot, dot multiplication, and the result is a scalar. The value after the corresponding component is multiplied.

A scalar is a new vector generated by multiplying each component of a vector by a scalar. (The vector is scaled down .)

Mul, matrix multiplication; matrix multiplied by vector or matrix.

Swizzle OPERATOR:

------- Float3 (A, B, C). ZYX yields float3 (C, B,)

------- Float4 (A, BC, d). xxyy yields float4 (a, a, B, B)

Texture lookups requires two partitions: texture sampler and texture coordinate.

-------- Texture sampler: sampler, sampler1d, sampler2d, sampler3d, samplercube, samplerect.

-------- Tex2d/rect/cube, nonprojective

-------- Text2d/rect/cubeproj, projective texture Lookup


Float, 32bit floating point number, s23e8 + 1bit

Halft, 16bit, s10e5

Int, 32 bit integer

Fixed, 12bit

Bool,

Sampler *, handle of texture object.

String

Vector and matrix.



Mul (MVP, POS) ----> convert the postion of vertex to the coordinates on the screen

Tex2d (texture, texcoordinate) ---------> output the color taken from our texture

Vertex output is the fragment input.


Screen rendering process:
1) Draw the screen to temporary texture, instead of the normal screen buffer.
2) Temporary texture is processed by the filter.
3) Put the processing result in the screen buffer and prepare to draw it to the screen for display to the user.

Related Article

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.