glsl

什么是顶点着色器?

The vertex processor is a programmable unit that operates on incoming vertices and their associated data.Compilation units written in the OpenGL Shading Language to run on this processor are called vertex shaders.When a set of vertex shaders are successfully compiled and linked, they result in a vertex shader executable that runs on the vertex processor.

The vertex processor operates on one vertex at a time. It does not replace graphics operations that require knowledge of several vertices at a time.

着色器代码需要utf-8编码格式

The source character set used for the OpenGL shading languages is Unicode in the UTF-8 encoding scheme.  

glsl支持c++ 标准预处理

There is a preprocessor that processes the source strings as part of the compilation process. Except as noted below, it behaves as the C++ standard preprocessor (see section 10 “Normative References”). 

The complete list of preprocessor directives is as follows.

#
#define
#undef
#if
#ifdef
#ifndef
#else
#elif
#endif
#error
#pragma
#extension
#version
#line
The following operators are also available
defined ##

一定支持1024一下的宏定义名称

Implementations must support macro-name lengths of up to 1024 characters. Implementations are allowed to generate an error for a macro name of length greater than 1024 characters, but are also allowed to support lengths greater than 1024. 

运算符优先级

glsl 关键字

The following are the language's keywords and (after preprocessing) can only be used as described in this specification, or a compile-time error results:
attribute const uniform varying buffer shared coherent volatile restrict readonly writeonly atomic_uint
layout
centroid flat smooth noperspective
patch sample
break continue do for while switch case default
if else
subroutine
in out inout
float double int void bool true false
invariant precise
discard return
mat2 mat3 mat4 dmat2 dmat3 dmat4
mat2x2 mat2x3 mat2x4 dmat2x2 dmat2x3 dmat2x4
mat3x2 mat3x3 mat3x4 dmat3x2 dmat3x3 dmat3x4
mat4x2 mat4x3 mat4x4 dmat4x2 dmat4x3 dmat4x4
vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 dvec2 dvec3 dvec4 uint uvec2 uvec3 uvec4

lowp mediump highp precision
sampler1D sampler2D sampler3D samplerCube
sampler1DShadow sampler2DShadow samplerCubeShadow
sampler1DArray sampler2DArray
sampler1DArrayShadow sampler2DArrayShadow
isampler1D isampler2D isampler3D isamplerCube
isampler1DArray isampler2DArray
usampler1D usampler2D usampler3D usamplerCube
usampler1DArray usampler2DArray
sampler2DRect sampler2DRectShadow isampler2DRect usampler2DRect samplerBuffer isamplerBuffer usamplerBuffer
sampler2DMS isampler2DMS usampler2DMS
sampler2DMSArray isampler2DMSArray usampler2DMSArray
samplerCubeArray samplerCubeArrayShadow isamplerCubeArray usamplerCubeArray image1D iimage1D uimage1D
image2D iimage2D uimage2D
image3D iimage3D uimage3D
image2DRect iimage2DRect uimage2DRect
imageCube iimageCube uimageCube
imageBuffer iimageBuffer uimageBuffer
image1DArray iimage1DArray uimage1DArray
image2DArray iimage2DArray uimage2DArray
imageCubeArray iimageCubeArray uimageCubeArray
image2DMS iimage2DMS uimage2DMS
image2DMSArray iimage2DMSArray uimage2DMSArray
struct

The following are the keywords reserved for future use. Using them will result in a compile-time error:
common partition active
asm
class union enum typedef template this resource

goto
inline noinline public static extern external interface long short half fixed unsigned superp
input output
hvec2 hvec3 hvec4 fvec2 fvec3 fvec4
sampler3DRect
filter
sizeof cast
namespace using

不要使用连续的两个下划线作为标识符

In addition, all identifiers containing two consecutive underscores ( __ ) are reserved for use by underlying software layers. Defining such a name in a shader does not itself result in an error, but may result in unintended behaviors that stem from having multiple definitions of the same name.

标识符约束规则:

identifier: 
    nondigit
    identifier nondigit
     identifier digit
nondigit: one of
    _ a b c d e f g h i j k l mn o p q r s t u v w x y z
    AB C D E F G H I J K LM N O PQ R S T U V W X Y Z
digit: one of
    01 2 34 56 7 89

控制流程 Page22

For example:
main() {
       float a = ...;// this is uniform flow control
       if (a < b) {  // this expression is true for some fragments, not all
           ....;     // non-uniform flow control
       } else {
           ....;     // non-uniform flow control
       }
       ....;         // uniform flow control again
   }
原文地址:https://www.cnblogs.com/afraidToForget/p/8000827.html