Shader built-in variables and functions

Source: Internet
Author: User

1. UINT Createshader (enum type): Creates an empty shader object;
Type:vertex_shader,
2, void Shadersource (UINT shader, Sizeicount, const **string, const int *length): Load shader source into shader object; possibly multiple strings
3, void Compileshader (UINT shader): Compile shader object;
Shader object has a status indicating the result of the compilation
4, void Deleteshader (UINT shader): Delete shader object;
5, void Shaderbinary (Sizei count, const UINT *shaders,
Enum Binaryformat, const void *binary, Sizei length): Loads pre-compiled shader binary strings;
6, uint Createprogram (void): Create an empty program object, Programe object organization multiple shader object, become executable;
7. Void Attachshader (UINT program, UINT shader): Associative shader object and program object;
8, void Detachshader (UINT program, UINT shader): disassociate;
9, void Linkprogram (UINT program): The program object is ready to execute, its associated shader object must compile correctly and meet the constraints;
10, void Useprogram (UINT program): Execute program object;
11. Void Programparameteri (UINT program, enum PName,
int value): Sets the parameter of program object;
12, void Deleteprogram (UINT program): Delete program object;
13, the qualifier of shader variable:
Default: No modifier, normal variable read and write, and no connection to the outside world;
Const: Constant const VEC3 Zaxis = VEC3 (0.0, 0.0, 1.0);
attribute: Declare the variable passed to vertex shader; Read only; cannot be an array or struct;attribute VEC4 position;
Uniform: Indicates the same value in the whole entity processing, read-only, uniform vec4 lightpos;
Varying: By the difference, reading and writing, varying vec3 normal;
In, out, inout;
14, the accuracy of shader variable:
HIGHP, Mediump, LOWP

15. Shader built-in variables:
Gl_position: Used for vertex shader, writing vertex position, being used in fixed operation functions such as collection and cropping of elements;
Its internal statement is: HIGHP VEC4 gl_position;
Gl_pointsize: For vertex shader, the point size after the rasterization, the number of pixels;
Its internal statement is: Mediump float gl_position;
Gl_fragcolor: Used for fragment shader, write fragment color, and be used by subsequent fixed pipelines;
Mediump VEC4 Gl_fragcolor;
Gl_fragdata: For fragment shader, is the number of groups, write Gl_fragdata[n] for the data n; be used by subsequent fixed pipelines;
Mediump VEC4 Gl_fragdata[gl_maxdrawbuffers];
Gl_fragcolor and Gl_fragdata are mutually exclusive and do not write at the same time;
Gl_fragcoord: For fragment shader, read-only, fragment relative to the coordinate position of the window x,y,z,1/w; This is generated after the fixed line element difference, Z is the depth value; Mediump VEC4 Gl_fragcoord;
Gl_frontfacing: Used to judge whether fragment belongs to front-facing primitive;
BOOL gl_frontfacing;
Gl_pointcoord: for point Primitive only; Mediump VEC2 Gl_pointcoord;
16. Shader built-in constants:
const Mediump INT gl_maxvertexattribs = 8;
const Mediump INT gl_maxvertexuniformvectors = 128;
const Mediump INT gl_maxvaryingvectors = 8;
const Mediump int gl_maxvertextextureimageunits = 0;
const Mediump INT gl_maxcombinedtextureimageunits = 8;
const Mediump INT gl_maxtextureimageunits = 8;
const Mediump INT gl_maxfragmentunitformvectors = 16;
const Mediump int gl_maxdrawbuffers = 1;
17. Shader built-in function:
The general default is in radians;
Radians (degree): Angle variable radian;
Degrees (radian): radian variable angle;
Sin (angle), cos (angle), tan (angle)
ASIN (x): Arc sine, return radians [-PI/2, PI/2];
ACOs (x): Arc cosine, return radians [0, PI];
Atan (y, x): Arc tangent, return radians [-pi, PI];
Atan (y/x): Arc tangent, return radians [-PI/2, PI/2];

Pow (x, y): X's y-square;
EXP (x): Exponent, log (x):
EXP2 (x): 2 x-Square, log2 (x):
sqrt (x): the radical of X; inversesqrt (x): The reciprocal of the X-root

ABS (x): Absolute value
Sign (x): symbol, 1, 0 or-1

A sign (x) or symbol (x) is called a symbolic function, and in mathematical and computer operations, it is the function of taking a number of symbols (positive or negative):
When x>0,sign (x) = 1;
When x=0,sign (x) = 0;
When x<0, sign (x) =-1;} Floor (x): Bottom Rounding
Ceil (x): Top rounding
Fract (x): Take a decimal part
MoD (x, y): modulo, x-y*floor (×/x)
Min (x, y): Take minimum value
Max (x, y): Take the maximum value
Clamp (x, Min, max): Min (max (x, Min), max);
Mix (x, Y, a): X, y linear aliasing, X (1-a) + y*a;
Step (Edge, X): 0.0 if x<edge, otherwise 1.0
Smoothstep (EDGE0, Edge1, x): used when Threshod smooth transition. Edge0<x<edge1 smoothing Difference, 0.0 at X&LT;=EDGE0, 1.0 at X>=edge1

Length (x): vector lengths
Distance (P0, p1): Two point distance, length (P0-P1);
Dot (x, y): dot product, each component is multiplied and then added
Cross (x, y): Differential product, x[1]*y[2]-y[1]*x[2], x[2]*y[0]-y[2]*x[0], x[0]*y[1]-y[0]*x[1]
Normalize (x): Normalized, Length (x) = 1;
Faceforward (n, I, nref): such as dot (Nref, i) < 0 N, otherwise-n
Reflect (I, N): The reflection direction of I, I-2*dot (n, I) *n, n must be normalized first
Refract (i, N, ETA): Refraction, k=1.0-eta*eta* (1.0-dot (n, i) * DOT (n, i)); If k<0.0 is 0.0, otherwise eta*i-(Eta*dot (N, I) +sqrt (k)) *n

Matrixcompmult (mATX, Maty): Multiply the matrix by multiplying each component by itself, i.e. R [j] = x[J]*y[j];
Linear multiplication of matrices, directly using *

LessThan (VECX, vecy): Vector per component comparison x < Y
Lessthanequal (VECX, vecy): Vector per component comparison X<=y
GreaterThan (VECX, vecy): Vector per component comparison X>y
Greaterthanequal (VECX, vecy): Vector per component comparison X>=y
Equal (VECX, vecy): Vector per component comparison X==y
NotEqual (VECX, vexy): Vector per component comparison X!=y
Any (BVECX): True if one component is true
All (BVECX): True if all components are true
Not (BVECX): All components take the inverse

Texture2d (sampler2d, coord): Texture Lookup
Texture2d (sampler2d, coord, bias): LOD bias, mip-mapped texture
Texture2dproj (sampler2d, coord):
Texture2dproj (sampler2d, coord, bias):
Texture2dlod (sampler2d, Coord, LOD):
Texture2dprojlod (sampler2d, Coord, LOD):
Texturecube (Samplercube, coord):
Texturecube (Samplercube, coord, bias):
Texturecubelod (Samplercube, Coord, LOD):

Shader built-in variables and functions

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.