beiklive's blog beiklive's blog
首页
  • 语言学习

    • C/C++
    • Python
    • Qt
  • 系统&引擎

    • Linux
    • Godot
  • 啥都学

    • 夏姬八学
    • 好好学习
  • 折腾记录

    • 树莓派
    • Obsidian
    • 实践记录
  • 技术文档
  • 工具网站
  • Github项目
  • 友情链接
  • 关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

beiklive

全沾艺人
首页
  • 语言学习

    • C/C++
    • Python
    • Qt
  • 系统&引擎

    • Linux
    • Godot
  • 啥都学

    • 夏姬八学
    • 好好学习
  • 折腾记录

    • 树莓派
    • Obsidian
    • 实践记录
  • 技术文档
  • 工具网站
  • Github项目
  • 友情链接
  • 关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 着色器 - 修改指定位置颜色
  • gdscript 常用代码片段
  • 着色器 - 图片像素化
  • 着色器学习(零) 基础简介
  • 着色器学习(一) 基本语法
  • 着色器学习(二) 内建变量
  • 着色器学习(三) 内建函数
  • 着色器学习(四) 一些内建变量的使用
  • Note_Godot
beiklive
2024-05-15

着色器学习(三) 内建函数

前一篇

05.着色器学习(二) 内建变量

参考地址:https://docs.godotengine.org/en/4.1/tutorials/shaders/shader_reference/shading_language.html

查找表(使用chatgpt辅助生成)

函数 描述 使用范例
radians 将角度转换为弧度。 vec_type angle_in_radians = radians(angle_in_degrees);
degrees 将弧度转换为角度。 vec_type angle_in_degrees = degrees(angle_in_radians);
sin 正弦。 vec_type sine_value = sin(angle);
cos 余弦。 vec_type cosine_value = cos(angle);
tan 正切。 vec_type tangent_value = tan(angle);
asin 反正弦。 vec_type angle = asin(value);
acos 反余弦。 vec_type angle = acos(value);
atan 反正切。 vec_type angle = atan(y_over_x);
atan (重载) 反正切。 vec_type angle = atan(y, x);
sinh 双曲正弦。 vec_type sinh_value = sinh(x);
cosh 双曲余弦。 vec_type cosh_value = cosh(x);
tanh 双曲正切。 vec_type tanh_value = tanh(x);
asinh 反双曲正弦。 vec_type x = asinh(value);
acosh 反双曲余弦。 vec_type x = acosh(value);
atanh 反双曲正切。 vec_type x = atanh(value);
pow 幂运算(如果 x < 0 或 x == 0 且 y <= 0,则结果未定义)。 vec_type result = pow(base, exponent);
exp Base-e 指数函数。 vec_type result = exp(x);
exp2 Base-2 指数函数。 vec_type result = exp2(x);
log 自然对数函数。 vec_type result = log(x);
log2 Base-2 对数函数。 vec_type result = log2(x);
sqrt 平方根函数。 vec_type result = sqrt(x);
inversesqrt 平方根的倒数函数。 vec_type result = inversesqrt(x);
abs 绝对值函数(对于负数返回正值)。 vec_type result = abs(x);
abs (整数版本) 绝对值函数(对于负数返回正值)。 ivec_type result = abs(x);
sign 符号函数(正数返回1.0,负数返回-1.0,零返回0.0)。 vec_type result = sign(x);
sign (整数版本) 符号函数(正数返回1,负数返回-1,零返回0)。 ivec_type result = sign(x);
floor 向下取整函数。 vec_type result = floor(x);
round 四舍五入到最近的整数。 vec_type result = round(x);
roundEven 四舍五入到最近的偶数。 vec_type result = roundEven(x);
trunc 截断到整数。 vec_type result = trunc(x);
ceil 向上取整函数。 vec_type result = ceil(x);
fract 返回小数部分(等同于 x - floor(x))。 vec_type result = fract(x);
mod 取模运算,返回除法余数。 vec_type result = mod(x, y);
mod (单个浮点数) 取模运算,返回除法余数。 vec_type result = mod(x, y);
modf 返回小数部分和整数部分。 vec_type fractional;
vec_type integral;
vec_type result = modf(x, integral);
min 返回两个值中的较小值。 vec_type result = min(a, b);
max 返回两个值中的较大值。 vec_type result = max(a, b);
clamp 将值限制在指定范围内。 vec_type result = clamp(x, min_value, max_value);
mix (浮点数版本) 线性插值,取值范围为 [a, b] 之间的值,c 为插值因子。 vec_type result = mix(a, b, c);
mix (向量版本) 线性插值,取值范围为 [a, b] 之间的值,c 为插值因子。 vec_type result = mix(a, b, condition_vector);
fma 执行融合乘加操作:(a * b + c)。 vec_type result = fma(a, b, c);
step 如果 b[i] < a[i],返回 0.0,否则返回 1.0。 vec_type result = step(a, b);
step (浮点数版本) 如果 b < a,返回 0.0,否则返回 1.0。 vec_type result = step(a, b);
smoothstep Hermite 插值,根据 c 在 [a, b] 范围内的位置进行插值。 vec_type result = smoothstep(a, b, c);
isnan 检查标量或向量组件是否为 NaN。 bvec_type result = isnan(x);
isinf 检查标量或向量组件是否为 INF。 bvec_type result = isinf(x);
floatBitsToInt 浮点到整数的位复制,无转换。 ivec_type result = floatBitsToInt(x);
floatBitsToUint 浮点到无符号整数的位复制,无转换。 uvec_type result = floatBitsToUint(x);
intBitsToFloat 整数到浮点的位复制,无转换。 vec_type result = intBitsToFloat(x);
uintBitsToFloat 无符号整数到浮点的位复制,无转换。 vec_type result = uintBitsToFloat(x);
length 计算向量的长度。 float result = length(x);
distance 计算向量之间的距离,即 length(a - b)。 float result = distance(a, b);
dot 计算两个向量的点积。 float result = dot(a, b);
cross 计算两个三维向量的叉积。 vec3 result = cross(a, b);
normalize 将向量归一化为单位长度。 vec_type result = normalize(x);
reflect 计算向量相对于法线的反射。 vec3 result = reflect(I, N);
refract 计算向量相对于法线的折射。 vec3 result = refract(I, N, eta);
faceforward 如果 dot(Nref, I) < 0,则返回 N,否则返回 -N。 vec_type result = faceforward(N, I, Nref);
matrixCompMult 矩阵分量乘法。 mat_type result = matrixCompMult(x, y);
outerProduct 外积矩阵。 mat_type result = outerProduct(column, row);
transpose 转置矩阵。 mat_type result = transpose(m);
determinant 计算矩阵的行列式。 float result = determinant(m);
inverse 计算矩阵的逆矩阵。 mat_type result = inverse(m);
lessThan 向量比较,如果 x[i] < y[i],返回 true。 bvec_type result = lessThan(x, y);
greaterThan 向量比较,如果 x[i] > y[i],返回 true。 bvec_type result = greaterThan(x, y);
lessThanEqual 向量比较,如果 x[i] <= y[i],返回 true。 bvec_type result = lessThanEqual(x, y);
greaterThanEqual 向量比较,如果 x[i] >= y[i],返回 true。 bvec_type result = greaterThanEqual(x, y);
equal 向量比较,如果 x[i] == y[i],返回 true。 bvec_type result = equal(x, y);
notEqual 向量比较,如果 x[i] != y[i],返回 true。 bvec_type result = notEqual(x, y);
any 如果向量的任何组件为 true,则返回 true。 bool result = any(x);
all 如果向量的所有组件为 true,则返回 true。 bool result = all(x);
not 反转布尔向量。 bvec_type result = not(x);
textureSize 获取纹理的大小。 ivec2 result = textureSize(s, lod);
textureSize 获取纹理的大小。 ivec3 result = textureSize(s, lod);
textureSize 获取纹理的大小。 ivec3 result = textureSize(s, lod);
textureSize 获取纹理的大小。 ivec2 result = textureSize(s, lod);
textureSize 获取纹理的大小。 ivec2 result = textureSize(s, lod);
textureQueryLod 计算用于采样纹理的细节级别。 vec2 result = textureQueryLod(s, p);
textureQueryLod 计算用于采样纹理的细节级别。 vec3 result = textureQueryLod(s, p);
textureQueryLod 计算用于采样纹理的细节级别。 vec2 result = textureQueryLod(s, p);
textureQueryLod 计算用于采样纹理的细节级别。 vec2 result = textureQueryLod(s, p);
textureQueryLevels 获取纹理的可访问细节级别数。 int result = textureQueryLevels(s);
textureQueryLevels 获取纹理的可访问细节级别数。 int result = textureQueryLevels(s);
textureQueryLevels 获取纹理的可访问细节级别数。 int result = textureQueryLevels(s);
textureQueryLevels 获取纹理的可访问细节级别数。 int result = textureQueryLevels(s);
texture 执行纹理读取。 gvec4_type result = texture(s, p, bias);
texture 执行纹理读取。 gvec4_type result = texture(s, p, bias);
texture 执行纹理读取。 gvec4_type result = texture(s, p, bias);
texture 执行纹理读取。 vec4 result = texture(s, p, bias);
texture 执行纹理读取。 vec4 result = texture(s, p, bias);
textureProj 执行带投影的纹理读取。 gvec4_type result = textureProj(s, p, bias);
textureProj 执行带投影的纹理读取。 gvec4_type result = textureProj(s, p, bias);
textureProj 执行带投影的纹理读取。 gvec4_type result = textureProj(s, p, bias);
textureLod 在自定义细节级别处执行纹理读取。 gvec4_type result = textureLod(s, p, lod);
textureLod 在自定义细节级别处执行纹理读取。 gvec4_type result = textureLod(s, p, lod);
textureLod 在自定义细节级别处执行纹理读取。 gvec4_type result = textureLod(s, p, lod);
textureLod 在自定义细节级别处执行纹理读取。 vec4 result = textureLod(s, p, lod);
textureLod 在自定义细节级别处执行纹理读取。 vec4 result = textureLod(s, p, lod);
textureProjLod 带有投影和自定义细节级别的纹理读取。 gvec4_type result = textureProjLod(s, p, lod);
textureProjLod 带有投影和自定义细节级别的纹理读取。 gvec4_type result = textureProjLod(s, p, lod);
textureProjLod 带有投影和自定义细节级别的纹理读取。 gvec4_type result = textureProjLod(s, p, lod);
textureGrad 带有显式梯度的纹理读取。 gvec4_type result = textureGrad(s, p, dPdx, dPdy);
textureGrad 带有显式梯度的纹理读取。 gvec4_type result = textureGrad(s, p, dPdx, dPdy);
textureGrad 带有显式梯度的纹理读取。 gvec4_type result = textureGrad(s, p, dPdx, dPdy);
textureGrad 带有显式梯度的纹理读取。 vec4 result = textureGrad(s, p, dPdx, dPdy);
textureGrad 带有显式梯度的纹理读取。 vec4 result = textureGrad(s, p, dPdx, dPdy);
textureProjGrad 执行带有投影/LOD和显式梯度的纹理读取。 gvec4_type result = textureProjGrad(s, p, dPdx, dPdy);
textureProjGrad 执行带有投影/LOD和显式梯度的纹理读取。 gvec4_type result = textureProjGrad(s, p, dPdx, dPdy);
textureProjGrad 执行带有投影/LOD和显式梯度的纹理读取。 gvec4_type result = textureProjGrad(s, p, dPdx, dPdy);
texelFetch 使用整数坐标提取单个纹理元素。 gvec4_type result = texelFetch(s, ivec2(p), lod);
texelFetch 使用整数坐标提取单个纹理元素。 gvec4_type result = texelFetch(s, ivec3(p), lod);
texelFetch 使用整数坐标提取单个纹理元素。 gvec4_type result = texelFetch(s, ivec3(p), lod);
textureGather 从纹理中聚集四个纹素。 gvec4_type result = textureGather(s, p, comps);
textureGather 从纹理中聚集四个纹素。 gvec4_type result = textureGather(s, p, comps);
textureGather 从纹理中聚集四个纹素。 vec4 result = textureGather(s, p, comps);
dFdx 使用局部差分计算相对于 x 窗口坐标的导数。 vec_type result = dFdx(p);
dFdxCoarse 使用局部差分基于当前片元邻居的值计算相对于 x 窗口坐标的导数。 vec_type result = dFdxCoarse(p);
dFdxFine 使用局部差分基于当前片元及其相邻片元的值计算相对于 x 窗口坐标的导数。 vec_type result = dFdxFine(p);
dFdy 使用局部差分计算相对于 y 窗口坐标的导数。 vec_type result = dFdy(p);
dFdyCoarse 使用局部差分基于当前片元邻居的值计算相对于 y 窗口坐标的导数。 vec_type result = dFdyCoarse(p);
dFdyFine 使用局部差分基于当前片元及其相邻片元的值计算相对于 y 窗口坐标的导数。 vec_type result = dFdyFine(p);
fwidth x 和 y 方向上的绝对导数之和。 vec_type result = fwidth(p);
fwidthCoarse x 和 y 方向上的绝对导数之和(基于粗糙差分)。 vec_type result = fwidthCoarse(p);
fwidthFine x 和 y 方向上的绝对导数之和(基于精细差分)。 vec_type result = fwidthFine(p);
uint packHalf2x16 (vec2 v) 将两个 32 位浮点数转换为 16 位并打包成一个 32 位无符号整数,反之亦然。 uint packed = packHalf2x16(vec2(0.5, 0.75));
vec2 unpackHalf2x16 (uint v) 将一个 32 位无符号整数解包成两个 16 位浮点数。 vec2 unpacked = unpackHalf2x16(packed);
uint packUnorm2x16 (vec2 v) 将两个 32 位浮点数(限制在 0 到 1 范围内)转换为 16 位并打包成一个 32 位无符号整数,反之亦然。 uint packed = packUnorm2x16(vec2(0.5, 0.75));
vec2 unpackUnorm2x16 (uint v) 将一个 32 位无符号整数解包成两个 16 位浮点数(范围在 0 到 1 之间)。 vec2 unpacked = unpackUnorm2x16(packed);
uint packSnorm2x16 (vec2 v) 将两个 32 位浮点数(限制在 -1 到 1 范围内)转换为 16 位并打包成一个 32 位无符号整数,反之亦然。 uint packed = packSnorm2x16(vec2(0.5, -0.75));
vec2 unpackSnorm2x16 (uint v) 将一个 32 位无符号整数解包成两个 16 位浮点数(范围在 -1 到 1 之间)。 vec2 unpacked = unpackSnorm2x16(packed);
uint packUnorm4x8 (vec4 v) 将四个 32 位浮点数(限制在 0 到 1 范围内)转换为 8 位并打包成一个 32 位无符号整数,反之亦然。 uint packed = packUnorm4x8(vec4(0.1, 0.5, 0.8, 1.0));
vec4 unpackUnorm4x8 (uint v) 将一个 32 位无符号整数解包成四个 8 位浮点数(范围在 0 到 1 之间)。 vec4 unpacked = unpackUnorm4x8(packed);
uint packSnorm4x8 (vec4 v) 将四个 32 位浮点数(限制在 -1 到 1 范围内)转换为 8 位并打包成一个 32 位无符号整数,反之亦然。 uint packed = packSnorm4x8(vec4(0.1, -0.5, 0.8, 1.0));
vec4 unpackSnorm4x8 (uint v) 将一个 32 位无符号整数解包成四个 8 位浮点数(范围在 -1 到 1 之间)。 vec4 unpacked = unpackSnorm4x8(packed);
ivec_type bitfieldExtract (ivec_type value, int offset, int bits) 从整数中提取一定范围的位。 ivec_type extracted = bitfieldExtract(value, 2, 4);
ivec_type bitfieldInsert (ivec_type base, ivec_type insert, int offset, int bits) 将一定范围的位插入到整数中。 ivec_type result = bitfieldInsert(base, insert, 2, 4);
ivec_type bitfieldReverse (ivec_type value) 反转整数中位的顺序。 ivec_type reversed = bitfieldReverse(value);
ivec_type bitCount (ivec_type value) 计算整数中值为 1 的位的数量。 ivec_type count = bitCount(value);
ivec_type findLSB (ivec_type value) 找到整数中最低有效位(值为 1)的索引。 ivec_type lsb = findLSB(value);
ivec_type findMSB (ivec_type value) 找到整数中最高有效位(值为 1)的索引。 ivec_type msb = findMSB(value);
void imulExtended (ivec_type x, ivec_type y, out ivec_type msb, out ivec_type lsb) 将两个 32 位数字相乘,生成一个 64 位结果。 imulExtended(5, 3, msb, lsb);
void umulExtended (uvec_type x, uvec_type y, out uvec_type msb, out uvec_type lsb) 将两个无符号整数相乘,生成一个 64 位结果。 umulExtended(5u, 3u, msb, lsb);
uvec_type uaddCarry (uvec_type x, uvec_type y, out uvec_type carry) 将两个无符号整数相加,并生成进位。 uvec_type sum = uaddCarry(5u, 3u, carry);
uvec_type usubBorrow (uvec_type x, uvec_type y, out uvec_type borrow) 将两个无符号整数相减,并生成借位。 uvec_type difference = usubBorrow(5u, 3u, borrow);
vec_type ldexp (vec_type x, out ivec_type exp) 从值和指数中组装浮点数。 vec_type result = ldexp(0.75, exp);
vec_type frexp (vec_type x, out ivec_type exp) 将浮点数拆分为尾数和整数指数。 vec_type significand = frexp(0.75, exp);
编辑 (opens new window)
#godot#着色器
上次更新: 2024/05/22, 14:11:38
着色器学习(二) 内建变量
着色器学习(四) 一些内建变量的使用

← 着色器学习(二) 内建变量 着色器学习(四) 一些内建变量的使用→

最近更新
01
爬虫技术与法律风险:个人开发者的注意事项
05-22
02
个人开发者的抉择:个人工作室 vs 公司主体 🤔
05-22
03
《计算机网络,自顶向下方法》笔记(一)
05-20
更多文章>
Theme by Vdoing | Copyright © 2024-2024 beiklive | 苏ICP备20038092号-2
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式