glsl version 300es 关键字

参考链接: GLSL_ES_Specification_3.00


变量名

不能要以gl_开头


注释

// 或 /**/


关键字

void float int uint bool

void function_name(){};
float var_name = 1.;
uint var_name = 1u;
const int numLights = 5;
float lights[numLights] = float[5](3.4, 4.2, 5.0, 5.2, 1.1);
float[5] foo() { ...}

struct

struct light {
 float intensity;
 vec3 position;
} lightVar;
light lightVar2;

struct T {
	S; // Error: anonymous structures disallowed
	struct { ... }; // Error: embedded structures disallowed
	S s; // Allowed: nested structure with a name.
};

**

mat2 mat3 mat4
mat2x2 mat2x3 mat2x4
mat3x2 mat3x3 mat3x4
mat4x2 mat4x3 mat4x4
vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3
bvec4
uvec2 uvec3 uvec4

uniform mat4 projectMatrix;
vec4 color = vec4(1.0,0.0,0.0,1.0)

sampler2D sampler3D samplerCube
sampler2DShadow samplerCubeShadow
sampler2DArray
sampler2DArrayShadow
isampler2D isampler3D isamplerCube
isampler2DArray
usampler2D usampler3D usamplerCube
usampler2DArray

uniform sampler2D diffuseMap;

uniform

uniform mat4 modelMatrix;

layout

//vertex shader
layout (location = 0) in vec3 aPos; 
layout (location = 1) in vec2 aTexCoords; 
//
layout(location = 3) out vec4 color;

centroid flat smooth


//flat : 
//栅格化时无插值,因此,在对特定图元进行栅格化期间生成的每个片段都将冲一个点获得相同的数据
//顶点着色器输出整数或无符号整数时不会插值,所以必须使用限定符flat
//vertexshader
flat out vec3 myColor;
//fragment shader
flat in vec3 myColor;
--------
//centroid :质心采样,默认中心采样
//使插值出现在图元内部,多重采样时防止出现伪像
//https://weekly-geekly.github.io/articles/434046/index.html
centroid in float myMixer; 
//smooth:
//平滑着色,栅格化时线性插值

The presence of and type of interpolation is controlled by the storage qualifiers centroid in and centroid out, and by the optional interpolation qualifiers smooth and flat. When no interpolation qualifier is present, smooth interpolation is used. It is a compile-time error to use more than one interpolation qualifier. A variable qualified as flat will not be interpolated. Instead, it will have the same value for every fragment within a triangle. This value will come from a single provoking vertex, as described by the OpenGL ES Graphics System Specification. A variable may be qualified as flat centroid, which will mean the same thing as qualifying it only as flat. A variable qualified as smooth will be interpolated in a perspective-correct manner over the primitive being rendered. Interpolation in a perspective correct manner is specified in equations 3.4 in the OpenGL ES 3.0 Graphics System Specification, section 3.5 “Line Segments”. This paragraph only applies if interpolation is being done: If single-sampling, the value is interpolated to the pixel’s center, and the centroid qualifier, if present, is ignored. If multi-sampling and the variable is not qualified with centroid, then the value must be interpolated to the pixel’s center, or anywhere within the pixel, or to one of the pixel’s samples. If multi-sampling and the variable is qualified with centroid, then the value must be interpolated to a point that lies in both the pixel and in the primitive being rendered, or to one of the pixel’s samples that falls within the primitive. Due to the less regular location of centroids, their derivatives may be less accurate than non-centroid interpolated variables. The type and presence of the interpolation qualifiers and storage qualifiers of variables with the same name declared in all linked shaders must match, otherwise the link command will fail.

in out inout

//vertex shader
out vec2 vUv;
out vec3 vNormal;
//fragment shader
in vec2 vUv;
in vec3 vNormal;
//function
vec4 f(in vec4 x, out vec4 y);

break continue do for while switch case default if else true false discard return

if(condition){
	discard;//销毁当前像素
}

invariant const

vec4 col;
vec2 a = ...
...
col = texture(tex, a); // a has a value a1
...
col = texture(tex, a); // a has a value a2 where possibly a1 ≠ a2
由于glsl的优化,导致值不一定一样所有有时可能需要invariant

//Example 3:
invariant gl_Position; // 使内建变量gl_Position 不可变
out vec3 Color;
invariant Color; // 使变量Color不可变

lowp mediump highp precision

precision mediump;
highp mat4 m;

以下关键字保留在将来使用,使用它们会报错
attribute varying
coherent volatile restrict readonly writeonly
resource atomic_uint
noperspective
patch sample
subroutine
common partition active
asm
class union enum typedef template this
goto
inline noinline volatile public static extern external interface
long short double half fixed unsigned superp
input output
hvec2 hvec3 hvec4 dvec2 dvec3 dvec4 fvec2 fvec3 fvec4
sampler3DRect
filter
image1D image2D image3D imageCube
iimage1D iimage2D iimage3D iimageCube
uimage1D uimage2D uimage3D uimageCube
image1DArray image2DArray
iimage1DArray iimage2DArray uimage1DArray uimage2DArray
imageBuffer iimageBuffer uimageBuffer
sampler1D sampler1DShadow sampler1DArray sampler1DArrayShadow
isampler1D isampler1DArray usampler1D usampler1DArray
sampler2DRect sampler2DRectShadow isampler2DRect usampler2DRect
samplerBuffer isamplerBuffer usamplerBuffer
sampler2DMS isampler2DMS usampler2DMS
sampler2DMSArray isampler2DMSArray usampler2DMSArray
sizeof cast
namespace using


发布了3 篇原创文章 · 获赞 0 · 访问量 94

猜你喜欢

转载自blog.csdn.net/q871837010/article/details/104774471