Shader 函数可视化

栏目: 后端 · 发布时间: 7年前

内容简介:动画演示:

正弦运动y = sin(x)

Shader 函数可视化

余弦运动y = cos(x)

Shader 函数可视化

动画演示:

Shader 函数可视化

二、smoothstep

在两个值之间取埃尔米特插值(Hermite interpolation)link

描述:在 edge0edge1 之间取一个平缓的差值,在我们需要一个平滑的渐变的时候特别有用。

使用:当前值小于 edge0 ,取值为 0 。当前值大于 edge1 ,取值 1 。在这个区间内,取 edge0edge1 的差值。

float smoothstep(float edge0, float edge1, float x)  
vec2 smoothstep(vec2 edge0, vec2 edge1, vec2 x)  
vec3 smoothstep(vec3 edge0, vec3 edge1, vec3 x)  
vec4 smoothstep(vec4 edge0, vec4 edge1, vec4 x)

vec2 smoothstep(float edge0, float edge1, vec2 x)  
vec3 smoothstep(float edge0, float edge1, vec3 x)  
vec4 smoothstep(float edge0, float edge1, vec4 x)
复制代码

它等同于:

genType t;  /* Or genDType t; */
t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
复制代码

可视化呈现: y = smoothstep(0.0,1.0,x);

Shader 函数可视化

将值限制在两个其他值谷歌之间

三、clamp

将值限制在两个其他值之间。link

说明: clamp() 返回 minValmaxVal 范围内的值。返回值计算:min(max(x, minVal), maxVal)。

使用:

float clamp(float x, float minVal, float maxVal)  
vec2 clamp(vec2 x, vec2 minVal, vec2 maxVal)  
vec3 clamp(vec3 x, vec3 minVal, vec3 maxVal)  
vec4 clamp(vec4 x, vec4 minVal, vec4 maxVal)

vec2 clamp(vec2 x, float minVal, float maxVal)  
vec3 clamp(vec3 x, float minVal, float maxVal)  
vec4 clamp(vec4 x, float minVal, float maxVal)
复制代码

可视化呈现: y = clamp(x,0.,1.);

Shader 函数可视化

四、step

通过比较两个值生成步进函数。link

说明: step() 通过将 xedge 进行比较来生成步进函数。对于返回值 i ,如果 x[i] < edge[i] 则返回 0.0 ,否则返回 1.0

使用:

float step(float edge, float x)  
vec2 step(vec2 edge, vec2 x)  
vec3 step(vec3 edge, vec3 x)  
vec4 step(vec4 edge, vec4 x)

vec2 step(float edge, vec2 x)  
vec3 step(float edge, vec3 x)  
vec4 step(float edge, vec4 x)
复制代码

可视化呈现: y = step(0.5,x);

Shader 函数可视化

五、mix

将值限制在两个其他值之间。link

描述:在 xy 之间执行线性插值,使用 a 来计算它们之间的权重。返回值的计算方式是: x*(1−a)+y*a

使用:

float mix(float x, float y, float a)  
vec2 mix(vec2 x, vec2 y, vec2 a)  
vec3 mix(vec3 x, vec3 y, vec3 a)  
vec4 mix(vec4 x, vec4 y, vec4 a)

vec2 mix(vec2 x, vec2 y, float a)  
vec3 mix(vec3 x, vec3 y, float a)  
vec4 mix(vec4 x, vec4 y, float a)
复制代码

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Mechanics of Web Handling

The Mechanics of Web Handling

David R. Roisum

This unique book covers many aspects of web handling for manufacturing, converting, and printing. The book is applicable to any web including paper, film, foil, nonwovens, and textiles. The Mech......一起来看看 《The Mechanics of Web Handling》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具