外观
GLSL API 查询
查询 GLSL 4.60 第 8 章内置函数与第 7 章常用阶段变量。展开条目查看重载、中文说明和 Khronos 规范章节。
桌面 Core、Compatibility、GLSL ES 和面向 Vulkan 的 GLSL 存在差异。此处以桌面 GLSL 4.60 为基准,兼容模式、已弃用和 Vulkan 专用函数带有说明。WebGL 适用版本可查 WebGL 1.0 或 WebGL 2.0。
角度与三角函数
radians将角度转换为弧度,常用于给三角函数准备参数。
genFType radians(genFType degrees)degrees将弧度转换为角度。
genFType degrees(genFType radians)sin求弧度的正弦,可用于周期动画和方向计算。
genFType sin(genFType angle)cos求弧度的余弦。
genFType cos(genFType angle)tan求弧度的正切。
genFType tan(genFType angle)asin求反正弦,输入范围为 −1 到 1。
genFType asin(genFType x)acos求反余弦,归一化方向的点积可以用它换算为夹角。
genFType acos(genFType x)atan单参数求反正切。双参数 atan(y, x) 按坐标决定象限。
genFType atan(genFType y, genFType x)
genFType atan(genFType y_over_x)sinh求双曲正弦。
genFType sinh(genFType x)cosh求双曲余弦。
genFType cosh(genFType x)tanh求双曲正切。
genFType tanh(genFType x)asinh求反双曲正弦。
genFType asinh(genFType x)acosh求反双曲余弦,输入至少为 1。
genFType acosh(genFType x)atanh求反双曲正切,输入绝对值小于 1。
genFType atanh(genFType x)指数与对数
pow求 x 的 y 次幂。负底数与零底的部分输入组合结果未定义。
genFType pow(genFType x, genFType y)exp求 e 的 x 次幂。
genFType exp(genFType x)log求正数的自然对数。
genFType log(genFType x)exp2求 2 的 x 次幂。
genFType exp2(genFType x)log2求正数的以 2 为底的对数。
genFType log2(genFType x)sqrt求非负值的平方根。
genFType sqrt(genFType x)
genDType sqrt(genDType x)inversesqrt求正数平方根的倒数。
genFType inversesqrt(genFType x)
genDType inversesqrt(genDType x)通用数学
abs逐分量求绝对值。
genFType abs(genFType x)
genIType abs(genIType x)
genDType abs(genDType x)sign将各分量的符号映射为 −1、0 或 1。
genFType sign(genFType x)
genIType sign(genIType x)
genDType sign(genDType x)floor向负无穷方向取整,例如 floor(−1.2) 为 −2。
genFType floor(genFType x)
genDType floor(genDType x)trunc向零取整,例如 trunc(−1.2) 为 −1。
genFType trunc(genFType x)
genDType trunc(genDType x)round舍入到最近整数,恰好位于中点时舍入方向由实现选择。
genFType round(genFType x)
genDType round(genDType x)roundEven舍入到最近整数,中点取相邻的偶数。
genFType roundEven(genFType x)
genDType roundEven(genDType x)ceil向正无穷方向取整。
genFType ceil(genFType x)
genDType ceil(genDType x)fract返回 x − floor(x);负输入通常也得到非负小数部分。
genFType fract(genFType x)
genDType fract(genDType x)mod按 x − y × floor(x / y) 计算浮点模,可用于周期坐标。
genFType mod(genFType x, float y)
genFType mod(genFType x, genFType y)
genDType mod(genDType x, double y)
genDType mod(genDType x, genDType y)modf返回带符号的小数部分,通过输出参数写入整数部分。
genFType modf(genFType x, out genFType i)
genDType modf(genDType x, out genDType i)min逐分量选取较小值。
genFType min(genFType x, genFType y)
genFType min(genFType x, float y)
genDType min(genDType x, genDType y)
genDType min(genDType x, double y)
genIType min(genIType x, genIType y)
genIType min(genIType x, int y)
genUType min(genUType x, genUType y)
genUType min(genUType x, uint y)max逐分量选取较大值。
genFType max(genFType x, genFType y)
genFType max(genFType x, float y)
genDType max(genDType x, genDType y)
genDType max(genDType x, double y)
genIType max(genIType x, genIType y)
genIType max(genIType x, int y)
genUType max(genUType x, genUType y)
genUType max(genUType x, uint y)clamp将输入限制在最小值和最大值之间。
genFType clamp(genFType x, genFType minVal, genFType maxVal)
genFType clamp(genFType x, float minVal, float maxVal)
genDType clamp(genDType x, genDType minVal, genDType maxVal)
genDType clamp(genDType x, double minVal, double maxVal)
genIType clamp(genIType x, genIType minVal, genIType maxVal)
genIType clamp(genIType x, int minVal, int maxVal)
genUType clamp(genUType x, genUType minVal, genUType maxVal)
genUType clamp(genUType x, uint minVal, uint maxVal)mix按权重线性插值。布尔重载用掩码逐分量选择。
genFType mix(genFType x, genFType y, genFType a)
genFType mix(genFType x, genFType y, float a)
genDType mix(genDType x, genDType y, genDType a)
genDType mix(genDType x, genDType y, double a)
genFType mix(genFType x, genFType y, genBType a)
genDType mix(genDType x, genDType y, genBType a)
genIType mix(genIType x, genIType y, genBType a)
genUType mix(genUType x, genUType y, genBType a)
genBType mix(genBType x, genBType y, genBType a)step输入小于阈值时返回 0,其余返回 1,可生成硬边遮罩。
genFType step(genFType edge, genFType x)
genFType step(float edge, genFType x)
genDType step(genDType edge, genDType x)
genDType step(double edge, genDType x)smoothstep在两个边界间执行 Hermite 平滑插值,可生成柔边遮罩。要求低边界小于高边界。
genFType smoothstep(genFType edge0, genFType edge1, genFType x)
genFType smoothstep(float edge0, float edge1, genFType x)
genDType smoothstep(genDType edge0, genDType edge1, genDType x)
genDType smoothstep(double edge0, double edge1, genDType x)isnan逐分量检测 NaN。
genBType isnan(genFType x)
genBType isnan(genDType x)isinf逐分量检测正或负无穷。
genBType isinf(genFType x)
genBType isinf(genDType x)floatBitsToInt把浮点位模式解释为有符号整数。
genIType floatBitsToInt(highp genFType value)floatBitsToUint把浮点位模式解释为无符号整数。
genUType floatBitsToUint(highp genFType value)intBitsToFloat将有符号整数位模式解释成浮点值。
genFType intBitsToFloat(highp genIType value)uintBitsToFloat将无符号整数位模式解释成浮点值。
genFType uintBitsToFloat(highp genUType value)fma计算 a × b + c;对 precise 结果保留融合运算的语义。
genFType fma(genFType a, genFType b, genFType c)
genDType fma(genDType a, genDType b, genDType c)frexp分解浮点值,返回尾数并通过输出参数提供二进制指数。
genFType frexp(highp genFType x, out highp genIType exp) genDType frexp(genDType x, out genIType exp)ldexp将浮点值乘以 2 的指定整数次幂,可用于合并 frexp 的结果。
genFType ldexp(highp genFType x, highp genIType exp)
genDType ldexp(genDType x, genIType exp)数值打包与解包
packUnorm2x16把两个 [0, 1] 范围内的浮点分量量化成 16 位无符号归一化值,并打包为 uint。
highp uint packUnorm2x16(vec2 v)packSnorm2x16将两个 [−1, 1] 范围内的分量量化成 16 位有符号归一化值并打包。
highp uint packSnorm2x16(vec2 v)packUnorm4x8将四个 [0, 1] 范围内的分量量化并打包,每分量 8 位。
uint packUnorm4x8(vec4 v)packSnorm4x8将四个 [−1, 1] 范围内的分量量化并打包,每分量 8 位。
uint packSnorm4x8(vec4 v)unpackUnorm2x16从 uint 取两个 16 位无符号归一化值,转换为 [0, 1] 浮点分量。
vec2 unpackUnorm2x16(highp uint p)unpackSnorm2x16从 uint 取两个 16 位有符号归一化值,转换为 [−1, 1] 浮点分量。
vec2 unpackSnorm2x16(highp uint p)unpackUnorm4x8将四个打包的 8 位无符号归一化值恢复为 [0, 1] 浮点分量。
vec4 unpackUnorm4x8(highp uint p)unpackSnorm4x8将四个打包的 8 位有符号归一化值恢复为 [−1, 1] 浮点分量。
vec4 unpackSnorm4x8(highp uint p)packHalf2x16把两个浮点分量转成 16 位半精度位模式,打包为一个 uint。
uint packHalf2x16( vec2 v)unpackHalf2x16解读两个打包的半精度浮点位模式,返回 vec2。
vec2 unpackHalf2x16( uint v)packDouble2x32把 uvec2 的低字和高字组合,并按位解释为 double。
double packDouble2x32(uvec2 v)unpackDouble2x32将 double 的位模式拆成两个 uint,低字在前。
uvec2 unpackDouble2x32(double v)向量几何
length求向量的欧几里得长度。
float length(genFType x)
double length(genDType x)distance求两点的欧几里得距离。
float distance(genFType p0, genFType p1)
double distance(genDType p0, genDType p1)dot求点积。归一化方向的点积是夹角余弦。
float dot(genFType x, genFType y)
double dot(genDType x, genDType y)cross求两个三维向量的叉积,结果垂直于输入张成的平面。
vec3 cross(vec3 x, vec3 y)
dvec3 cross(dvec3 x, dvec3 y)normalize将非零向量缩放为单位长度,方向保持一致。
genFType normalize(genFType x)
genDType normalize(genDType x)ftransform按固定管线惯例变换顶点,仅供兼容模式的顶点着色器使用。
vec4 ftransform()faceforward按参考法线与入射方向的点积符号,选择法线或反向法线。
genFType faceforward(genFType N, genFType I, genFType Nref)
genDType faceforward(genDType N, genDType I, genDType Nref)reflect根据入射方向与单位法线计算反射方向。
genFType reflect(genFType I, genFType N)
genDType reflect(genDType I, genDType N)refract根据入射方向、单位法线和折射率之比求折射方向。全反射时返回零向量。
genFType refract(genFType I, genFType N, float eta)
genDType refract(genDType I, genDType N, double eta)矩阵
matrixCompMult对两个同型矩阵逐元素相乘。
mat matrixCompMult(mat x, mat y)outerProduct对列向量和行向量求外积,得到矩阵。
mat2 outerProduct(vec2 c, vec2 r)
mat3 outerProduct(vec3 c, vec3 r)
mat4 outerProduct(vec4 c, vec4 r)
mat2x3 outerProduct(vec3 c, vec2 r)
mat3x2 outerProduct(vec2 c, vec3 r)
mat2x4 outerProduct(vec4 c, vec2 r)
mat4x2 outerProduct(vec2 c, vec4 r)
mat3x4 outerProduct(vec4 c, vec3 r)
mat4x3 outerProduct(vec3 c, vec4 r)transpose交换矩阵的行列。
mat2 transpose(mat2 m)
mat3 transpose(mat3 m)
mat4 transpose(mat4 m)
mat2x3 transpose(mat3x2 m)
mat3x2 transpose(mat2x3 m)
mat2x4 transpose(mat4x2 m)
mat4x2 transpose(mat2x4 m)
mat3x4 transpose(mat4x3 m)
mat4x3 transpose(mat3x4 m)determinant求方阵的行列式。
float determinant(mat2 m)
float determinant(mat3 m)
float determinant(mat4 m)inverse求可逆方阵的逆。奇异或病态矩阵的结果未定义。
mat2 inverse(mat2 m)
mat3 inverse(mat3 m)
mat4 inverse(mat4 m)向量比较与布尔运算
lessThan逐分量比较 x 是否小于 y,返回布尔向量。
bvec lessThan(vec x, vec y)
bvec lessThan(ivec x, ivec y)
bvec lessThan(uvec x, uvec y)lessThanEqual逐分量比较 x 是否小于等于 y。
bvec lessThanEqual(vec x, vec y)
bvec lessThanEqual(ivec x, ivec y)
bvec lessThanEqual(uvec x, uvec y)greaterThan逐分量比较 x 是否大于 y。
bvec greaterThan(vec x, vec y)
bvec greaterThan(ivec x, ivec y)
bvec greaterThan(uvec x, uvec y)greaterThanEqual逐分量比较 x 是否大于等于 y。
bvec greaterThanEqual(vec x, vec y)
bvec greaterThanEqual(ivec x, ivec y)
bvec greaterThanEqual(uvec x, uvec y)equal逐分量比较向量元素是否相等。
bvec equal(vec x, vec y)
bvec equal(ivec x, ivec y)
bvec equal(uvec x, uvec y)
bvec equal(bvec x, bvec y)notEqual逐分量比较向量元素是否不相等。
bvec notEqual(vec x, vec y)
bvec notEqual(ivec x, ivec y)
bvec notEqual(uvec x, uvec y)
bvec notEqual(bvec x, bvec y)any判断布尔向量中是否存在 true。
bool any(bvec x)all判断布尔向量的每个分量是否为 true。
bool all(bvec x)not逐分量反转布尔向量。
bvec not(bvec x)整数与位操作
uaddCarry执行无符号加法,返回低 32 位并输出进位。
genUType uaddCarry(highp genUType x, highp genUType y, out lowp genUType carry)usubBorrow执行无符号减法,返回低 32 位并输出借位。
genUType usubBorrow(highp genUType x, highp genUType y, out lowp genUType borrow)umulExtended进行无符号乘法,通过输出参数写入积的高位和低位。
void umulExtended(highp genUType x, highp genUType y, out highp genUType msb, out highp genUType lsb)imulExtended进行有符号乘法,通过输出参数写入积的高位和低位。
void imulExtended(highp genIType x, highp genIType y, out highp genIType msb, out highp genIType lsb)bitfieldExtract从指定偏移提取一段位域,有符号重载对结果进行符号扩展。
genIType bitfieldExtract(genIType value, int offset, int bits)
genUType bitfieldExtract(genUType value, int offset, int bits)bitfieldInsert用插入值的低位替换原值中指定偏移和宽度的位域。
genIType bitfieldInsert(genIType base, genIType insert, int offset, int bits)
genUType bitfieldInsert(genUType base, genUType insert, int offset, int bits)bitfieldReverse反转各整数分量内部的位顺序。
genIType bitfieldReverse(highp genIType value)
genUType bitfieldReverse(highp genUType value)bitCount统计各整数分量中值为 1 的位数。
genIType bitCount(genIType value)
genIType bitCount(genUType value)findLSB返回最低有效 1 的位索引;零返回 −1。
genIType findLSB(genIType value)
genIType findLSB(genUType value)findMSB求最高有效位索引。负的有符号输入查找最高的 0;零或有符号的 −1 返回 −1。
genIType findMSB(highp genIType value)
genIType findMSB(highp genUType value)纹理查询
textureSize查询指定 mip 级的纹理尺寸,数组重载还返回层数。
int textureSize(gsampler1D sampler, int lod)
ivec2 textureSize(gsampler2D sampler, int lod)
ivec3 textureSize(gsampler3D sampler, int lod)
ivec2 textureSize(gsamplerCube sampler, int lod)
int textureSize(sampler1DShadow sampler, int lod)
ivec2 textureSize(sampler2DShadow sampler, int lod)
ivec2 textureSize(samplerCubeShadow sampler, int lod) ivec3 textureSize(gsamplerCubeArray sampler, int lod)
ivec3 textureSize(samplerCubeArrayShadow sampler, int lod)
ivec2 textureSize(gsampler2DRect sampler)
ivec2 textureSize(sampler2DRectShadow sampler)
ivec2 textureSize(gsampler1DArray sampler, int lod)
ivec2 textureSize(sampler1DArrayShadow sampler, int lod)
ivec3 textureSize(gsampler2DArray sampler, int lod)
ivec3 textureSize(sampler2DArrayShadow sampler, int lod)
int textureSize(gsamplerBuffer sampler)
ivec2 textureSize(gsampler2DMS sampler)
ivec3 textureSize(gsampler2DMSArray sampler)textureQueryLod在片元阶段查询采样将使用的 LOD 信息。
vec2 textureQueryLod(gsampler1D sampler, float P)
vec2 textureQueryLod(gsampler2D sampler, vec2 P)
vec2 textureQueryLod(gsampler3D sampler, vec3 P)
vec2 textureQueryLod(gsamplerCube sampler, vec3 P)
vec2 textureQueryLod(gsampler1DArray sampler, float P)
vec2 textureQueryLod(gsampler2DArray sampler, vec2 P)
vec2 textureQueryLod(gsamplerCubeArray sampler, vec3 P)
vec2 textureQueryLod(sampler1DShadow sampler, float P)
vec2 textureQueryLod(sampler2DShadow sampler, vec2 P)
vec2 textureQueryLod(samplerCubeShadow sampler, vec3 P)
vec2 textureQueryLod(sampler1DArrayShadow sampler, float P)
vec2 textureQueryLod(sampler2DArrayShadow sampler, vec2 P)
vec2 textureQueryLod(samplerCubeArrayShadow sampler, vec3 P)textureQueryLevels查询纹理可访问的 mip 层数。
int textureQueryLevels(gsampler1D sampler)
int textureQueryLevels(gsampler2D sampler)
int textureQueryLevels(gsampler3D sampler)
int textureQueryLevels(gsamplerCube sampler)
int textureQueryLevels(gsampler1DArray sampler)
int textureQueryLevels(gsampler2DArray sampler)
int textureQueryLevels(gsamplerCubeArray sampler)
int textureQueryLevels(sampler1DShadow sampler)
int textureQueryLevels(sampler2DShadow sampler)
int textureQueryLevels(samplerCubeShadow sampler)
int textureQueryLevels(sampler1DArrayShadow sampler)
int textureQueryLevels(sampler2DArrayShadow sampler)
int textureQueryLevels(samplerCubeArrayShadow sampler)textureSamples查询多重采样纹理的样本数。
int textureSamples(gsampler2DMS sampler)
int textureSamples(gsampler2DMSArray sampler)纹理采样与纹素读取
texture按采样器状态和纹理坐标采样。片元阶段可使用隐式导数选择 mip,也有比较采样重载。
在非一致控制流中依赖隐式导数可能得到未定义结果。可以在分支之前计算梯度,再用 textureGrad。
gvec4 texture(gsampler1D sampler, float P [, float bias] )
gvec4 texture(gsampler2D sampler, vec2 P [, float bias] )
gvec4 texture(gsampler3D sampler, vec3 P [, float bias] )
gvec4 texture(gsamplerCube sampler, vec3 P[, float bias] )
float texture(sampler1DShadow sampler, vec3 P [, float bias])
float texture(sampler2DShadow sampler, vec3 P [, float bias])
float texture(samplerCubeShadow sampler, vec4 P [, float bias] )
gvec4 texture(gsampler2DArray sampler, vec3 P [, float bias] )
gvec4 texture(gsamplerCubeArray sampler, vec4 P [, float bias] )
gvec4 texture(gsampler1DArray sampler, vec2 P [, float bias] )
float texture(sampler1DArrayShadow sampler, vec3 P [, float bias] )
float texture(sampler2DArrayShadow sampler, vec4 P)
gvec4 texture(gsampler2DRect sampler, vec2 P)
float texture(sampler2DRectShadow sampler, vec3 P)
float texture(samplerCubeArrayShadow sampler, vec4 P, float compare)textureProj将采样坐标按最后一个分量投影,再做纹理采样。
gvec4 textureProj(gsampler1D sampler, vec2 P [, float bias] )
gvec4 textureProj(gsampler1D sampler, vec4 P [, float bias] )
gvec4 textureProj(gsampler2D sampler, vec3 P [, float bias] )
gvec4 textureProj(gsampler2D sampler, vec4 P [, float bias] )
gvec4 textureProj(gsampler3D sampler, vec4 P [, float bias] )
float textureProj(sampler1DShadow sampler, vec4 P [, float bias] )
float textureProj(sampler2DShadow sampler, vec4 P [, float bias] )
gvec4 textureProj(gsampler2DRect sampler, vec3 P)
gvec4 textureProj(gsampler2DRect sampler, vec4 P)
float textureProj(sampler2DRectShadow sampler, vec4 P)textureLod通过显式提供 LOD 选择纹理采样层级。
gvec4 textureLod(gsampler1D sampler, float P, float lod)
gvec4 textureLod(gsampler2D sampler, vec2 P, float lod)
gvec4 textureLod(gsampler3D sampler, vec3 P, float lod)
gvec4 textureLod(gsamplerCube sampler, vec3 P, float lod)
float textureLod(sampler2DShadow sampler, vec3 P, float lod)
float textureLod(sampler1DShadow sampler, vec3 P, float lod)
gvec4 textureLod(gsampler1DArray sampler, vec2 P, float lod)
float textureLod(sampler1DArrayShadow sampler, vec3 P, float lod)
gvec4 textureLod(gsampler2DArray sampler, vec3 P, float lod)
gvec4 textureLod(gsamplerCubeArray sampler, vec4 P, float lod)textureOffset用整数常量偏移移动纹素位置后采样。
gvec4 textureOffset(gsampler1D sampler, float P, int offset [, float bias] )
gvec4 textureOffset(gsampler2D sampler, vec2 P, ivec2 offset [, float bias] )
gvec4 textureOffset(gsampler3D sampler, vec3 P, ivec3 offset [, float bias] )
float textureOffset(sampler2DShadow sampler, vec3 P, ivec2 offset [, float bias] )
gvec4 textureOffset(gsampler2DRect sampler, vec2 P, ivec2 offset)
float textureOffset(sampler2DRectShadow sampler, vec3 P, ivec2 offset)
float textureOffset(sampler1DShadow sampler, vec3 P, int offset [, float bias] )
gvec4 textureOffset(gsampler1DArray sampler, vec2 P, int offset [, float bias] )
gvec4 textureOffset(gsampler2DArray sampler, vec3 P, ivec2 offset [, float bias] )
float textureOffset(sampler1DArrayShadow sampler, vec3 P, int offset [, float bias] )
float textureOffset(sampler2DArrayShadow sampler, vec4 P, ivec2 offset)texelFetch直接读取整数坐标的单个纹素,可指定 mip 或多重采样下标。
gvec4 texelFetch(gsampler1D sampler, int P, int lod)
gvec4 texelFetch(gsampler2D sampler, ivec2 P, int lod)
gvec4 texelFetch(gsampler3D sampler, ivec3 P, int lod) gvec4 texelFetch(gsampler2DRect sampler, ivec2 P)
gvec4 texelFetch(gsampler1DArray sampler, ivec2 P, int lod)
gvec4 texelFetch(gsampler2DArray sampler, ivec3 P, int lod)
gvec4 texelFetch(gsamplerBuffer sampler, int P)
gvec4 texelFetch(gsampler2DMS sampler, ivec2 P, int sample)
gvec4 texelFetch(gsampler2DMSArray sampler, ivec3 P, int sample)texelFetchOffset在整数纹素坐标上叠加规定的偏移,再直接读取。
gvec4 texelFetchOffset(gsampler1D sampler, int P, int lod, int offset)
gvec4 texelFetchOffset(gsampler2D sampler, ivec2 P, int lod, ivec2 offset)
gvec4 texelFetchOffset(gsampler3D sampler, ivec3 P, int lod, ivec3 offset)
gvec4 texelFetchOffset(gsampler2DRect sampler, ivec2 P, ivec2 offset)
gvec4 texelFetchOffset(gsampler1DArray sampler, ivec2 P, int lod, int offset)
gvec4 texelFetchOffset(gsampler2DArray sampler, ivec3 P, int lod, ivec2 offset)textureProjOffset投影坐标并施加整数纹素偏移后采样。
gvec4 textureProjOffset(gsampler1D sampler, vec2 P, int offset [, float bias] )
gvec4 textureProjOffset(gsampler1D sampler, vec4 P, int offset [, float bias] )
gvec4 textureProjOffset(gsampler2D sampler, vec3 P, ivec2 offset [, float bias] )
gvec4 textureProjOffset(gsampler2D sampler, vec4 P, ivec2 offset [, float bias] )
gvec4 textureProjOffset(gsampler3D sampler, vec4 P, ivec3 offset [, float bias] )
gvec4 textureProjOffset(gsampler2DRect sampler, vec3 P, ivec2 offset)
gvec4 textureProjOffset(gsampler2DRect sampler, vec4 P, ivec2 offset)
float textureProjOffset(sampler2DRectShadow sampler, vec4 P, ivec2 offset)
float textureProjOffset(sampler1DShadow sampler, vec4 P, int offset [, float bias] )
float textureProjOffset(sampler2DShadow sampler, vec4 P, ivec2 offset [, float bias] )textureLodOffset用显式 LOD 和整数纹素偏移采样。
gvec4 textureLodOffset(gsampler1D sampler, float P, float lod, int offset)
gvec4 textureLodOffset(gsampler2D sampler, vec2 P, float lod, ivec2 offset)
gvec4 textureLodOffset(gsampler3D sampler, vec3 P, float lod, ivec3 offset)
float textureLodOffset(sampler1DShadow sampler, vec3 P, float lod, int offset)
float textureLodOffset(sampler2DShadow sampler, vec3 P, float lod, ivec2 offset)
gvec4 textureLodOffset(gsampler1DArray sampler, vec2 P, float lod, int offset)
gvec4 textureLodOffset(gsampler2DArray sampler, vec3 P, float lod, ivec2 offset)
float textureLodOffset(sampler1DArrayShadow sampler, vec3 P, float lod, int offset)textureProjLod投影坐标后按显式 LOD 采样。
gvec4 textureProjLod(gsampler1D sampler, vec2 P, float lod)
gvec4 textureProjLod(gsampler1D sampler, vec4 P, float lod)
gvec4 textureProjLod(gsampler2D sampler, vec3 P, float lod)
gvec4 textureProjLod(gsampler2D sampler, vec4 P, float lod)
gvec4 textureProjLod(gsampler3D sampler, vec4 P, float lod)
float textureProjLod(sampler1DShadow sampler, vec4 P, float lod)
float textureProjLod(sampler2DShadow sampler, vec4 P, float lod)textureProjLodOffset投影采样,同时给出显式 LOD 和纹素偏移。
gvec4 textureProjLodOffset(gsampler1D sampler, vec2 P, float lod, int offset)
gvec4 textureProjLodOffset(gsampler1D sampler, vec4 P, float lod, int offset)
gvec4 textureProjLodOffset(gsampler2D sampler, vec3 P, float lod, ivec2 offset)
gvec4 textureProjLodOffset(gsampler2D sampler, vec4 P, float lod, ivec2 offset)
gvec4 textureProjLodOffset(gsampler3D sampler, vec4 P, float lod, ivec3 offset)
float textureProjLodOffset(sampler1DShadow sampler, vec4 P, float lod, int offset)
float textureProjLodOffset(sampler2DShadow sampler, vec4 P, float lod, ivec2 offset)textureGrad显式传入坐标在屏幕 x 和 y 方向上的梯度,用它们决定采样。
gvec4 textureGrad(gsampler1D sampler, float _P, float dPdx, float dPdy)
gvec4 textureGrad(gsampler2D sampler, vec2 P, vec2 dPdx, vec2 dPdy)
gvec4 textureGrad(gsampler3D sampler, vec3 P, vec3 dPdx, vec3 dPdy)
gvec4 textureGrad(gsamplerCube sampler, vec3 P, vec3 dPdx, vec3 dPdy)
gvec4 textureGrad(gsampler2DRect sampler, vec2 P, vec2 dPdx, vec2 dPdy)
float textureGrad(sampler2DRectShadow sampler, vec3 P, vec2 dPdx, vec2 dPdy)
float textureGrad(sampler1DShadow sampler, vec3 P, float dPdx, float dPdy)
gvec4 textureGrad(gsampler1DArray sampler, vec2 P, float dPdx, float dPdy)
gvec4 textureGrad(gsampler2DArray sampler, vec3 P, vec2 dPdx, vec2 dPdy)
float textureGrad(sampler1DArrayShadow sampler, vec3 P, float dPdx, float dPdy)
float textureGrad(sampler2DShadow sampler, vec3 P, vec2 dPdx, vec2 dPdy)
float textureGrad(samplerCubeShadow sampler, vec4 P, vec3 dPdx, vec3 dPdy)
float textureGrad(sampler2DArrayShadow sampler, vec4 P, vec2 dPdx, vec2 dPdy)
gvec4 textureGrad(gsamplerCubeArray sampler, vec4 P, vec3 dPdx, vec3 dPdy)textureGradOffset显式传入坐标梯度,同时偏移纹素位置。
gvec4 textureGradOffset(gsampler1D sampler, float P, float dPdx, float dPdy, int offset)
gvec4 textureGradOffset(gsampler2D sampler, vec2 P, vec2 dPdx, vec2 dPdy, ivec2 offset)
gvec4 textureGradOffset(gsampler3D sampler, vec3 P, vec3 dPdx, vec3 dPdy, ivec3 offset)
gvec4 textureGradOffset(gsampler2DRect sampler, vec2 P, vec2 dPdx, vec2 dPdy, ivec2 offset)
float textureGradOffset(sampler2DRectShadow sampler, vec3 P, vec2 dPdx, vec2 dPdy, ivec2 offset)
float textureGradOffset(sampler1DShadow sampler, vec3 P, float dPdx, float dPdy, int offset)
float textureGradOffset(sampler2DShadow sampler, vec3 P, vec2 dPdx, vec2 dPdy, ivec2 offset)
gvec4 textureGradOffset(gsampler2DArray sampler, vec3 P, vec2 dPdx, vec2 dPdy, ivec2 offset)
gvec4 textureGradOffset(gsampler1DArray sampler, vec2 P, float dPdx, float dPdy, int offset)
float textureGradOffset(sampler1DArrayShadow sampler, vec3 P, float dPdx, float dPdy, int offset)
float textureGradOffset(sampler2DArrayShadow sampler, vec4 P, vec2 dPdx, vec2 dPdy, ivec2 offset)textureProjGrad使用投影坐标和已投影的显式梯度执行采样。
gvec4 textureProjGrad(gsampler1D sampler, vec2 P, float dPdx, float dPdy)
gvec4 textureProjGrad(gsampler1D sampler, vec4 P, float dPdx, float dPdy)
gvec4 textureProjGrad(gsampler2D sampler, vec3 P, vec2 dPdx, vec2 dPdy)
gvec4 textureProjGrad(gsampler2D sampler, vec4 P, vec2 dPdx, vec2 dPdy)
gvec4 textureProjGrad(gsampler3D sampler, vec4 P, vec3 dPdx, vec3 dPdy)
gvec4 textureProjGrad(gsampler2DRect sampler, vec3 P, vec2 dPdx, vec2 dPdy)
gvec4 textureProjGrad(gsampler2DRect sampler, vec4 P, vec2 dPdx, vec2 dPdy)
float textureProjGrad(sampler2DRectShadow sampler, vec4 P, vec2 dPdx, vec2 dPdy)
float textureProjGrad(sampler1DShadow sampler, vec4 P, float dPdx, float dPdy)
float textureProjGrad(sampler2DShadow sampler, vec4 P, vec2 dPdx, vec2 dPdy)textureProjGradOffset在投影坐标与显式梯度采样中加入纹素偏移。
gvec4 textureProjGradOffset(gsampler1D sampler, vec2 P, float dPdx, float dPdy, int offset)
gvec4 textureProjGradOffset(gsampler1D sampler, vec4 P, float dPdx, float dPdy, int offset)
gvec4 textureProjGradOffset(gsampler2D sampler, vec3 P, vec2 dPdx, vec2 dPdy, ivec2 offset)
gvec4 textureProjGradOffset(gsampler2D sampler, vec4 P, vec2 dPdx, vec2 dPdy, ivec2 offset)
gvec4 textureProjGradOffset(gsampler3D sampler, vec4 P, vec3 dPdx, vec3 dPdy, ivec3 offset)
gvec4 textureProjGradOffset(gsampler2DRect sampler, vec3 P, vec2 dPdx, vec2 dPdy, ivec2 offset)
gvec4 textureProjGradOffset(gsampler2DRect sampler, vec4 P, vec2 dPdx, vec2 dPdy, ivec2 offset)
float textureProjGradOffset(sampler2DRectShadow sampler, vec4 P, vec2 dPdx, vec2 dPdy, ivec2 offset)
float textureProjGradOffset(sampler1DShadow sampler, vec4 P, float dPdx, float dPdy, int offset)
float textureProjGradOffset(sampler2DShadow sampler, vec4 P, vec2 dPdx, vec2 dPdy, ivec2 offset)纹理 Gather
textureGather从基准 mip 级的四个相邻纹素各收集同一通道,返回四分量向量。
gvec4 textureGather(gsampler2D sampler, vec2 P [, int comp])
gvec4 textureGather(gsampler2DArray sampler, vec3 P [, int comp])
gvec4 textureGather(gsamplerCube sampler, vec3 P [, int comp])
gvec4 textureGather(gsamplerCubeArray sampler, vec4 P[, int comp])
gvec4 textureGather(gsampler2DRect sampler, vec2 P[, int comp])
vec4 textureGather(sampler2DShadow sampler, vec2 P, float refZ)
vec4 textureGather(sampler2DArrayShadow sampler, vec3 P, float refZ)
vec4 textureGather(samplerCubeShadow sampler, vec3 P, float refZ)
vec4 textureGather(samplerCubeArrayShadow sampler, vec4 P, float refZ)
vec4 textureGather(sampler2DRectShadow sampler, vec2 P, float refZ)textureGatherOffset以相同偏移移动四个被收集的纹素。
gvec4 textureGatherOffset(gsampler2D sampler, vec2 P, ivec2 offset, [ int comp])
gvec4 textureGatherOffset(gsampler2DArray sampler, vec3 P, ivec2 offset [ int comp])
vec4 textureGatherOffset(sampler2DShadow sampler, vec2 P, float refZ, ivec2 offset)
vec4 textureGatherOffset(sampler2DArrayShadow sampler, vec3 P, float refZ, ivec2 offset)
gvec4 textureGatherOffset(gsampler2DRect sampler, vec2 P, ivec2 offset [ int comp])
vec4 textureGatherOffset(sampler2DRectShadow sampler, vec2 P, float refZ, ivec2 offset)textureGatherOffsets分别指定四个被收集纹素的偏移。
gvec4 textureGatherOffsets(gsampler2D sampler, vec2 P, ivec2 offsets[4] [, int comp])
gvec4 textureGatherOffsets(gsampler2DArray sampler, vec3 P, ivec2 offsets[4] [, int comp])
vec4 textureGatherOffsets(sampler2DShadow sampler, vec2 P, float refZ, ivec2 offsets[4])
vec4 textureGatherOffsets(sampler2DArrayShadow sampler, vec3 P, float refZ, ivec2 offsets[4])
gvec4 textureGatherOffsets(gsampler2DRect sampler, vec2 P, ivec2 offsets[4] [, int comp])
vec4 textureGatherOffsets(sampler2DRectShadow sampler, vec2 P, float refZ, ivec2 offsets[4])兼容模式的纹理函数
texture1D按一维坐标采样一维纹理。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 texture1D(sampler1D sampler, float coord [, float bias] )texture1DProj按投影坐标采样一维纹理。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 texture1DProj(sampler1D sampler, vec2 coord [, float bias] )
vec4 texture1DProj(sampler1D sampler, vec4 coord [, float bias] )texture1DLod按显式 LOD 采样一维纹理。用于桌面兼容模式。
texture1DProjLod用投影坐标与显式 LOD 采样一维纹理。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 texture1DProjLod(sampler1D sampler, vec2 coord, float lod)
vec4 texture1DProjLod(sampler1D sampler, vec4 coord, float lod)texture2D按二维坐标采样二维纹理。桌面 Core 的对应函数为 texture。
WebGL 1 的 GLSL ES 1.00 也有同名函数。WebGL 2 的 GLSL ES 3.00 使用 texture。
vec4 texture2D(sampler2D sampler, vec2 coord [, float bias] )texture2DProj按投影坐标采样二维纹理。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 texture2DProj(sampler2D sampler, vec3 coord [, float bias] )
vec4 texture2DProj(sampler2D sampler, vec4 coord [, float bias] )texture2DLod用显式 LOD 采样二维纹理。用于桌面兼容模式。
texture2DProjLod用投影坐标与显式 LOD 采样二维纹理。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 texture2DProjLod(sampler2D sampler, vec3 coord, float lod)
vec4 texture2DProjLod(sampler2D sampler, vec4 coord, float lod)texture3D按三维坐标采样三维纹理。用于桌面兼容模式。
texture3DProj按投影坐标采样三维纹理。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 texture3DProj(sampler3D sampler, vec4 coord [, float bias] )texture3DLod用显式 LOD 采样三维纹理。用于桌面兼容模式。
texture3DProjLod用投影坐标与显式 LOD 采样三维纹理。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 texture3DProjLod(sampler3D sampler, vec4 coord, float lod)textureCube按三维方向采样立方图。桌面 Core 的对应函数为 texture。
WebGL 1 的 GLSL ES 1.00 也有同名函数。WebGL 2 的 GLSL ES 3.00 使用 texture。
vec4 textureCube(samplerCube sampler, vec3 coord [, float bias] )textureCubeLod按方向和显式 LOD 采样立方图。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 textureCubeLod(samplerCube sampler, vec3 coord, float lod)shadow1D采样一维深度纹理并执行深度比较。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 shadow1D(sampler1DShadow sampler, vec3 coord [, float bias] )shadow2D采样二维深度纹理并执行深度比较。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 shadow2D(sampler2DShadow sampler, vec3 coord [, float bias] )shadow1DProj对投影坐标执行一维深度比较采样。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 shadow1DProj(sampler1DShadow sampler, vec4 coord [, float bias] )shadow2DProj对投影坐标执行二维深度比较采样。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 shadow2DProj(sampler2DShadow sampler, vec4 coord [, float bias] )shadow1DLod用显式 LOD 执行一维深度比较采样。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 shadow1DLod(sampler1DShadow sampler, vec3 coord, float lod)shadow2DLod用显式 LOD 执行二维深度比较采样。用于桌面兼容模式。
桌面 Compatibility Profile
vec4 shadow2DLod(sampler2DShadow sampler, vec3 coord, float lod)shadow1DProjLod用投影坐标和显式 LOD 执行一维深度比较采样。
桌面 Compatibility Profile
vec4 shadow1DProjLod(sampler1DShadow sampler, vec4 coord, float lod)shadow2DProjLod用投影坐标和显式 LOD 执行二维深度比较采样。
桌面 Compatibility Profile
vec4 shadow2DProjLod(sampler2DShadow sampler, vec4 coord, float lod)原子计数器
atomicCounterIncrement原子增加计数器,返回增加之前的值。
uint atomicCounterIncrement(atomic_uint c)atomicCounterDecrement原子减少计数器,返回减少之后的值。
uint atomicCounterDecrement(atomic_uint c)atomicCounter原子读取计数器当前值。
uint atomicCounter(atomic_uint c)atomicCounterAdd原子加上无符号值,返回原值。
uint atomicCounterAdd(atomic_uint c, uint data)atomicCounterSubtract原子减去无符号值,返回原值。
uint atomicCounterSubtract(atomic_uint c, uint data)atomicCounterMin用较小值更新原子计数器,返回原值。
uint atomicCounterMin(atomic_uint c, uint data)atomicCounterMax用较大值更新原子计数器,返回原值。
uint atomicCounterMax(atomic_uint c, uint data)atomicCounterAnd对原子计数器按位与,返回原值。
uint atomicCounterAnd(atomic_uint c, uint data)atomicCounterOr对原子计数器按位或,返回原值。
uint atomicCounterOr(atomic_uint c, uint data)atomicCounterXor对原子计数器按位异或,返回原值。
uint atomicCounterXor(atomic_uint c, uint data)atomicCounterExchange写入新的计数器值并返回原值。
uint atomicCounterExchange(atomic_uint c, uint data)atomicCounterCompSwap计数器值与比较值相等时原子写入新值,返回原值。
uint atomicCounterCompSwap(atomic_uint c, uint compare, uint data)内存原子操作
atomicAdd原子更新缓冲或共享内存中的整数,并返回原值。
uint atomicAdd(inout uint mem, uint data)
int atomicAdd(inout int mem, int data)atomicMin以两个整数中的较小值原子更新内存,返回原值。
uint atomicMin(inout uint mem, uint data)
int atomicMin(inout int mem, int data)atomicMax以两个整数中的较大值原子更新内存,返回原值。
uint atomicMax(inout uint mem, uint data)
int atomicMax(inout int mem, int data)atomicAnd在内存整数上执行原子按位与,返回原值。
uint atomicAnd(inout uint mem, uint data)
int atomicAnd(inout int mem, int data)atomicOr在内存整数上执行原子按位或,返回原值。
uint atomicOr(inout uint mem, uint data)
int atomicOr(inout int mem, int data)atomicXor在内存整数上执行原子按位异或,返回原值。
uint atomicXor(inout uint mem, uint data)
int atomicXor(inout int mem, int data)atomicExchange原子替换内存整数,返回原值。
uint atomicExchange(inout uint mem, uint data)
int atomicExchange(inout int mem, int data)atomicCompSwap内存值与比较值相等时原子替换,返回原值。
uint atomicCompSwap(inout uint mem, uint compare, uint data)
int atomicCompSwap(inout int mem, int compare, int data)图像读写与原子操作
imageSize查询 image 对象绑定到该图像单元的尺寸。
int imageSize(readonly writeonly gimage1D image)
ivec2 imageSize(readonly writeonly gimage2D image)
ivec3 imageSize(readonly writeonly gimage3D image)
ivec2 imageSize(readonly writeonly gimageCube image)
ivec3 imageSize(readonly writeonly gimageCubeArray image)
ivec3 imageSize(readonly writeonly gimage2DArray image)
ivec2 imageSize(readonly writeonly gimage2DRect image)
ivec2 imageSize(readonly writeonly gimage1DArray image)
ivec2 imageSize(readonly writeonly gimage2DMS image)
ivec3 imageSize(readonly writeonly gimage2DMSArray image)
int imageSize(readonly writeonly gimageBuffer image)imageSamples查询 image 的多重采样数。
int imageSamples(readonly writeonly gimage2DMS image)
int imageSamples(readonly writeonly gimage2DMSArray image)imageLoad按整数坐标读取图像单元中的纹素,支持按样本访问。
gvec4 imageLoad(readonly IMAGE_PARAMS)imageStore按整数坐标写入纹素,图像单元须允许写入。
void imageStore(writeonly IMAGE_PARAMS, gvec4 data)imageAtomicAdd对指定图像纹素执行原子加法,返回原值。
uint imageAtomicAdd(IMAGE_PARAMS, uint data)
int imageAtomicAdd(IMAGE_PARAMS, int data)imageAtomicMin用较小值原子更新纹素,返回原值。
uint imageAtomicMin(IMAGE_PARAMS, uint data)
int imageAtomicMin(IMAGE_PARAMS, int data)imageAtomicMax用较大值原子更新纹素,返回原值。
uint imageAtomicMax(IMAGE_PARAMS, uint data)
int imageAtomicMax(IMAGE_PARAMS, int data)imageAtomicAnd对纹素执行原子按位与,返回原值。
uint imageAtomicAnd(IMAGE_PARAMS, uint data)
int imageAtomicAnd(IMAGE_PARAMS, int data)imageAtomicOr对纹素执行原子按位或,返回原值。
uint imageAtomicOr(IMAGE_PARAMS, uint data)
int imageAtomicOr(IMAGE_PARAMS, int data)imageAtomicXor对纹素执行原子按位异或,返回原值。
uint imageAtomicXor(IMAGE_PARAMS, uint data)
int imageAtomicXor(IMAGE_PARAMS, int data)imageAtomicExchange用新值原子替换纹素,返回原值。
uint imageAtomicExchange(IMAGE_PARAMS, uint data)
int imageAtomicExchange(IMAGE_PARAMS, int data)
float imageAtomicExchange(IMAGE_PARAMS, float data)imageAtomicCompSwap纹素值与比较值相等时原子写入新值,返回原值。
uint imageAtomicCompSwap(IMAGE_PARAMS, uint compare, uint data)
int imageAtomicCompSwap(IMAGE_PARAMS, int compare, int data)几何着色器
EmitStreamVertex将几何着色器的输出写为指定流中的一个顶点。
EndStreamPrimitive在指定几何输出流中结束当前图元。
EmitVertex将几何着色器输出写为流 0 中的一个顶点。提交后要为下一顶点重新写入输出。
EndPrimitive结束流 0 中的当前几何图元。
片元导数
dFdx近似计算屏幕空间 x 方向的偏导,允许实现选择细粒度或粗粒度。
dFdy近似计算屏幕空间 y 方向的偏导,允许实现选择细粒度或粗粒度。
dFdxFine使用当前片元及其邻域近似 x 方向偏导。
dFdyFine使用当前片元及其邻域近似 y 方向偏导。
dFdxCoarse允许在局部区域内复用较粗粒度的 x 方向偏导。
dFdyCoarse允许在局部区域内复用较粗粒度的 y 方向偏导。
fwidth返回 abs(dFdx(p)) + abs(dFdy(p)),可用于按像素宽度做抗锯齿。
fwidthFine使用细粒度的两个方向偏导,求绝对值之和。
fwidthCoarse使用粗粒度的两个方向偏导,求绝对值之和。
片元插值
interpolateAtCentroid在落于图元覆盖范围内的质心采样位置取得插值。
仅片元阶段
float interpolateAtCentroid(float interpolant)
vec2 interpolateAtCentroid(vec2 interpolant)
vec3 interpolateAtCentroid(vec3 interpolant)
vec4 interpolateAtCentroid(vec4 interpolant)interpolateAtSample在指定多重采样样本位置取得插值。
仅片元阶段
float interpolateAtSample(float interpolant, int sample)
vec2 interpolateAtSample(vec2 interpolant, int sample)
vec3 interpolateAtSample(vec3 interpolant, int sample)
vec4 interpolateAtSample(vec4 interpolant, int sample)interpolateAtOffset按相对于像素中心的偏移取得插值。
仅片元阶段
float interpolateAtOffset(float interpolant, vec2 offset)
vec2 interpolateAtOffset(vec2 interpolant, vec2 offset)
vec3 interpolateAtOffset(vec3 interpolant, vec2 offset)
vec4 interpolateAtOffset(vec4 interpolant, vec2 offset)旧版噪声函数
noise1旧版标量噪声入口。GLSL 4.60 的非 SPIR-V 路径返回 0.0。
noise2旧版二维噪声入口。GLSL 4.60 的非 SPIR-V 路径返回全零 vec2。
noise3旧版三维噪声入口。GLSL 4.60 的非 SPIR-V 路径返回全零 vec3。
noise4旧版四维噪声入口。GLSL 4.60 的非 SPIR-V 路径返回全零 vec4。
执行同步
barrier让同一工作组或同一 patch 的着色器调用在执行点汇合。
内存同步
memoryBarrier为当前调用发出的相关内存访问建立顺序与可见性。
void memoryBarrier()memoryBarrierAtomicCounter为原子计数器存储的访问建立内存顺序。
void memoryBarrierAtomicCounter()memoryBarrierBuffer为缓冲变量的访问建立内存顺序。
void memoryBarrierBuffer()memoryBarrierImage为图像变量的访问建立内存顺序。
void memoryBarrierImage()groupMemoryBarrier将内存访问排序的作用范围限制在当前计算工作组。
Vulkan 子通道输入
subpassLoad在面向 Vulkan 的片元阶段,从当前片元位置读取子通道输入。
仅 Vulkan 片元阶段
gvec4 subpassLoad(gsubpassInput subpass)
gvec4 subpassLoad(gsubpassInputMS subpass, int sample)调用组投票
anyInvocation判断调用组的活动调用中是否至少有一个条件为真。
allInvocations判断调用组的所有活动调用是否都满足条件。
allInvocationsEqual判断调用组所有活动调用提交的布尔值是否一致。
顶点内置变量
gl_Position最后一个顶点处理阶段输出的齐次裁剪坐标。
out vec4 gl_Positiongl_PointSize启用着色器点大小时指定点图元直径。
out float gl_PointSizegl_ClipDistance可编程裁剪平面的有符号距离。
out float[] gl_ClipDistancegl_CullDistance图元剔除平面的有符号距离。
out float[] gl_CullDistancegl_VertexID当前顶点的索引,语义取决于绘制命令。
in int gl_VertexIDgl_InstanceID当前实例从零开始的序号。
in int gl_InstanceIDgl_DrawID多重绘制中当前绘制的序号。
in int gl_DrawIDgl_BaseVertex当前绘制的基准顶点值。
in int gl_BaseVertexgl_BaseInstance当前绘制的基准实例值。
in int gl_BaseInstance曲面细分内置变量
gl_PatchVerticesIn输入 patch 的控制点数量。
in int gl_PatchVerticesIngl_InvocationID控制阶段中当前调用的索引,也用于几何着色器调用。
in int gl_InvocationIDgl_TessLevelOuter控制阶段写入的外边缘细分级别,求值阶段读取。
float[4] gl_TessLevelOutergl_TessLevelInner控制阶段写入的内部细分级别,求值阶段读取。
float[2] gl_TessLevelInnergl_TessCoord求值阶段内,当前生成顶点在图元参数域中的坐标。
in vec3 gl_TessCoord几何内置变量
gl_PrimitiveIDIn几何着色器当前输入图元的序号。
in int gl_PrimitiveIDIngl_PrimitiveID几何阶段可以写入供片元阶段读取的图元编号。细分阶段也用该名称访问 patch 编号。
int gl_PrimitiveIDgl_Layer指定分层 framebuffer 的输出层。片元阶段也可读取。
out int gl_Layergl_ViewportIndex选择输出图元使用的视口索引。片元阶段也可读取。
out int gl_ViewportIndexgl_in几何阶段读取输入图元的顶点数据,曲面细分阶段也有相应输入块。
in gl_PerVertex[] gl_ingl_out曲面细分控制阶段输出每个控制点的数据。
out gl_PerVertex[] gl_out片元内置变量
gl_FragCoord片元窗口坐标、深度和裁剪空间 w 的倒数。
in vec4 gl_FragCoordgl_FrontFacing当前片元所属图元是否为正面。
in bool gl_FrontFacinggl_PointCoord点图元内两个范围为 0 到 1 的坐标分量。
in vec2 gl_PointCoordgl_FragDepth覆盖当前片元的深度值。
out float gl_FragDepthgl_SampleID当前样本索引。静态使用会启用逐样本求值。
in int gl_SampleIDgl_SamplePosition当前样本在像素内的位置。
in vec2 gl_SamplePositiongl_SampleMaskIn输入覆盖掩码,按位标识被覆盖的样本。
in int[] gl_SampleMaskIngl_SampleMask着色器输出的逐样本覆盖掩码。
out int[] gl_SampleMaskgl_HelperInvocation标识为支持导数等操作而产生的辅助片元调用。
in bool gl_HelperInvocation计算内置变量
gl_NumWorkGroups当前 dispatch 的三个维度上各有多少工作组。
in uvec3 gl_NumWorkGroupsgl_WorkGroupSize由 local_size 布局限定符声明的工作组尺寸。
const uvec3 gl_WorkGroupSizegl_WorkGroupID当前工作组在整个 dispatch 中的坐标。
in uvec3 gl_WorkGroupIDgl_LocalInvocationID当前调用在工作组中的三维坐标。
in uvec3 gl_LocalInvocationIDgl_GlobalInvocationID当前调用在整个 dispatch 中的三维坐标。
in uvec3 gl_GlobalInvocationIDgl_LocalInvocationIndex当前调用在组内展平后的线性索引。
in uint gl_LocalInvocationIndex阅读签名
Khronos 的通用签名使用类型占位符。例如 genFType 表示 float 或浮点向量 vec2、vec3、vec4。genIType、genUType、genDType、genBType 分别代表对应的有符号整数、无符号整数、双精度和布尔类型。gvec4 和 gsampler 的前缀可为空、i 或 u,表示浮点、有符号整数或无符号整数。方括号包裹的参数表示可选重载,具体阶段限制见原规范。
