OpenGL:Shader

OpenGL:Shader
vec4 v, u; mat4 m; v * u component - wise v * m v is row vector m * v v is column vector m * m linear - algebraic matrix multiplication Inverse 求逆 Transpose 转置 gl_ModelViewMatrixInverse; gl_ModelViewProjectionMatrixInverseTranspose gl_NormalMatrix is the transpose of the inverse of the gl_ModelViewMatrix. function prototype: vec4 fract(vec4 x); == x - floor(x); <- [ 0 , 1 ) // fract 片断 vec4 clamp( float x, float minVal, float maxVal); returns min(max(x, minVal), maxVal); vec4 mix(vec4 x, vec4 y, vec4 a); return x * ( 1.0 - a) + y * a; vec4 step(vec4 edge, vec4 x); returns 0 if x < edge, otherwise returns 1 . vec4 smoothstep(vec4 edge0, vec4 edge1, vec4 x); returns if x <= edge0, returns 1 if x >= edge1, perform hermite interpolation between 0 and 1 when edge0 < x < edge1 0到1之间的Hermite插值算法 equal to t = clamp((x - edge0) / (edge1 - edge0), 0.0 , 1.0 ); return t * t * ( 3 - 2 * t); vec3 cross(vec3 x, vec3 y); //  只有这种形式,即只有三个component的向量才行 dot(N, L); result[ 0 ] = x[ 1 ] * y[ 2 ] - x[ 2 ] * y[ 1 ]; result[ 1 ] = x[ 2 ] * y[ 0 ] - x[ 0 ] * y[ 2 ]; result[ 2 ] = x[ 0 ] * y[ 1 ] - x[ 1 ] * y[ 0 ]; float dot(vec4 x, vec4 y); result = x[ 0 ] * y[ 0 ] + x[ 1 ] * y[ 1 ] + ...; vec4 reflect(vec4 I, vec4 N); // 反射光线向量 For the incident vector I and surface orientation N, returns the reflection direction result = I - 2.0 * dot(N, I) * N; vec3 ecPosition = vec3 (gl_ModelViewMatrix * gl_Vertex); vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal); vec3 lightVec = normalize(LightPosition - ecPosition); vec3 reflectVec = reflect( - lightVec, tnorm); vec3 viewVec = normalize( - ecPosition); vec4 refract(vec4 I, vec4 N, float eta); // 折射光线向量 For the incident vector I and surface normal N and the ratio(比率) of refraction eta, returns the refraction vector. The returned result is computed as k = 1.0 - eta * eta * ( 1.0 - dot(N, I) * dot(N, I)); if (k < 0.0 ) { result = 0.0 ; // the return type is float of vec2/3/4 } else { result = eta * I - (eta * dot(N, I) * sqrt(k)) * N; } mat4 matrixComMult(mat4 x, mat4 y); component - wise to get linear - algebraic multiplication, use the multiply operator ( * ) mat4 x, y; x * y;

你可能感兴趣的:(OpenGL:Shader)