GLSL内置数学函数部分解析

阶跃函数

step函数:Generate a step function by comparing two values

For element i of the return value, 0.0 is returned if x[i] < edge[i], and 1.0 is returned otherwise.

edge specifies the location of the edge of the step function.

x specify the value to be used to generate the step function.

float step(float edge, float x);

在这里插入图片描述

平滑阶梯函数,平滑过渡函数

smoothstep函数:Perform Hermite interpolation between two values

    genType t;  /* Or genDType t; */
    t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
    return t * t * (3.0 - 2.0 * t);
inverse_smoothstep = 0.5 - sin(asin(1.0 - 2.0 * x) / 3.0);

edge0` specifies the value of the lower edge of the Hermite function.

edge1 specifies the value of the upper edge of the Hermite function.

x specifies the source value for interpolation.

float smoothstep(float edge0, float edge1 float x);

在这里插入图片描述

atan函数

atan会返回一个介于-PI到PI的弧度值(-3.14 to 3.14)

distance函数:

p0 specifies the first of two points

p1 specifies the second of two points

distance() returns the distance between the two points p0 and p1.

float distance(float p0, float p1);
float distance(vec2 p0, vec2 p1);
// The DISTANCE from the pixel to the center
pct = distance(st,vec2(0.5));
// The LENGTH of the vector from the pixel to the center ,vec2 toCenter = vec2(0.5)-st;
pct = length(toCenter);
// The SQUARE ROOT of the vector from the pixel to the center
vec2 tC = vec2(0.5)-st; 
pct = sqrt(tC.x*tC.x+tC.y*tC.y);

以上三种情况得到的是一样的结果!

length函数

x specifies a vector of which to calculate the length.

length() returns the length of the vector.

float length(float x)  
float length(vec2 x)  
float length(vec3 x)  
float length(vec4 x)

reflect:几何函数,根据入射方向和法向求反射方向

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值