昆明网站运营公司有哪些,网站系统怎么做,网站图怎么做才能小而清晰,cm域名做网站GLSL语言内置的变量#xff0c;包括内置的顶点属性#xff08;attribute#xff09;、一致变量#xff08;uniform#xff09;、易变变量#xff08;varying#xff09;以及常量#xff08;const#xff09;#xff0c;一方面加深印象#xff0c;另一方面今天的文章… GLSL语言内置的变量包括内置的顶点属性attribute、一致变量uniform、易变变量varying以及常量const一方面加深印象另一方面今天的文章可以为以后的编程做查询之用。顶点属性——指顶点的信息OpenGL据此绘制各个图元对于传统的顶点属性包括坐标、纹理坐标、颜色等GLSL都会设置一个内置变量与之对应以便在需要时可以在顶点或片元着色器中直接引用这也体现了GLSL与HLSL的一个最大的不同HLSL里顶点的属性是通过语义来定义的而GLSL充分考虑了OpenGL是个状态机这一事实将顶点属性设为一个状态变量。GLSL中内置的顶点属性包括以下几个// 顶点属性attribute vec4 gl_Color; // 顶点颜色attribute vec4 gl_SecondaryColor; // 辅助顶点颜色attribute vec3 gl_Normal; // 顶点法线attribute vec4 gl_Vertex; // 顶点物体空间坐标未变换attribute vec4 gl_MultiTexCoord[0-N]; // 顶点纹理坐标N gl_MaxTextureCoordsattribute float gl_FogCoord; // 顶点雾坐标值得一提的是用户可以调用glVertexAttrib设置自己的顶点属性当然个数是有限制的一致变量——就是常说的Uniform这是用户向GLSL传递自己数据的最常用方法比如光源位置等等。之所以称为一致变量是为了与易变变量相区别。不同于顶点属性在每个顶点有其自己的值也不同于易变变量由顶点程序向片元程序插值传递一致变量在一个图元的绘制过程中是不会改变的而且可以在顶点shader和片元shader间共享。这部分变量主要用来描述OpenGL的状态可以看作OpenGL状态机的复制。GLSL内置的一致变量包括// 矩阵状态uniform mat4 gl_ModelViewMatrix; // 模型视图变换矩阵uniform mat4 gl_ProjectMatrix; // 投影矩阵uniform mat4 gl_ModelViewProjectMatrix; // 模型视图投影变换矩阵ftransform()uniform mat3 gl_NormalMatrix; // 法向量变换到视空间矩阵uniform mat4 gl_TextureMatrix[gl_MatTextureCoords]; // 各纹理变换矩阵// 普通缩放因子uniform float gl_NormalScale;// 窗口坐标深度范围struct gl_DepthRangeParameters{ float near; float far; float diff; // far-near};uniform gl_DepthRangeParameters gl_DepthRange;// 裁剪平面uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];// 点属性struct gl_PointParameters{ float size; float sizeMin; float sizeMax; float fadeThresholdSize; float distanceConstantAttenuation; float distanceLinearAttenuation; float distanceQuadraticAttenuation;};uniform gl_PointParameters gl_Point;// 材质struct gl_MaterialParameters{ vec4 emission; // 自身光照Ecm vec4 ambient; // 环境光吸收系数Acm vec4 diffuse; // 漫反射吸收系数Dcm vec4 specular; // 镜面反射吸收系数Scm float shininess; // Srm};uniform gl_MaterialParameters gl_FrontMaterial; // 正面材质uniform gl_MaterialParameters gl_BackMaterial; // 反面材质// 光源性质参数性质就不解释了和OpenGL的三种光源性质是一样的struct gl_LightSourceParameters{ vec4 ambient; // Acii vec4 diffuse; // Dcii vec4 specular; // Scii vec4 position; // Ppii vec4 halfVector; // Hi vec3 spotDirection; // Sdli float spotExponent; // Srli float spotCutoff; // Crli float spotCosCutoff; // cos(Crli) float constantAttenuation; // K0 float linearAttenuation; // K1 float quadraticAttenuation; // K2};uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];struct gl_LightModelParameters{ vec4 ambient; // Acs};uniform gl_LightModelParameters gl_LightModel;// 光照和材质的派生状态struct gl_LightModelProducts{ vec4 sceneColor; // EcmAcm*Acs};uniform gl_LightModelProducts gl_FrontLightModelProduct;uniform gl_LightModelProducts gl_BackLightModelProduct;struct gl_LightProducts{ vec4 ambient; // Acm * Acli vec4 diffuse; // Dcm * Dcli vec4 specular; // Scm * Scli};uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];// 纹理环境和生成unifrom vec4 gl_TextureEnvColor[gl_MaxTextureImageUnits];unifrom vec4 gl_EyePlaneS[gl_MaxTextureCoords]; unifrom vec4 gl_EyePlaneT[gl_MaxTextureCoords];unifrom vec4 gl_EyePlaneR[gl_MaxTextureCoords];unifrom vec4 gl_EyePlaneQ[gl_MaxTextureCoords];unifrom vec4 gl_ObjectPlaneS[gl_MaxTextureCoords];unifrom vec4 gl_ObjectPlaneT[gl_MaxTextureCoords];unifrom vec4 gl_ObjectPlaneR[gl_MaxTextureCoords];unifrom vec4 gl_ObjectPlaneQ[gl_MaxTextureCoords];// 雾参数struct gl_FogParameters{ vec4 color; float density; float start; float end; float scale; // 1/(end-start)};uniform gl_FogParameters gl_Fog;易变变量——易变变量只能在顶点shader和片元shader间传递这期间实际上经过了一个光栅化的过程。内置的易变变量比较少如下varying vec4 gl_Color;varying vec4 gl_SecondaryColor;varying vec4 gl_TexCoord[gl_MaxTextureCoords];varying float gl_FogFragCoord;熟悉图形管线的话可以自己描绘出这些易变变量是如何在顶点和片元程序间进行传递的。内置常量——内置常量描述了显卡的渲染能力依据各个显卡而定这里就不一一列举了如果想要查询的话可以用OpenGL的glGet函数获取一族的常量值这些值和内置变量的值是一致的。1.texture2D//texture2D对纹理进行采样(得到一个纹素texel这是一个纹理图片中的像素。函数参数分别为simpler2D以及纹理坐标) gl_FragColor texture2D(inputImageTexture, textureCoordinate);2.dot 它实质是计算光的强度由于dot实质是计算两向量的夹角余弦所以当角度〉90度时为负值。090度时为正值3.pow(x,y) 计算x的y次方。两个值都为float。 转载于:https://blog.51cto.com/2119784/962118