Godot Shader 05-了解shader

工作原理

对一个矩形区域操作
cpu下的代码执行方式:(依次执行)

for x in range(width):
  for y in range(height):
    set_color(x, y, some_color)

gpu执行方式: (并发执行)
每个像素都会执行一次这个函数

void fragment() {
  COLOR = some_color;
}

gpu运算优缺点

优点:

  • 位置顶点处理速度飞快
  • 处理颜色速度飞快
  • 处理光照效果速度飞快
  • 可处理大量的数学计算

缺点:

  • 不能网格外绘制
  • 不能在当前像素/顶点下处理其他像素/顶点
  • 不能存储上一次效果
  • 不能热更新? (update on the fly (they can, but they need to be compiled))

结构

godot下只有三个主函数vertex(), fragment(), light()
vertex()对每个网格上的顶点都进行处理
·fragment()·对每个像素处理
·light()·对光的反应进行处理

猜你喜欢

转载自blog.csdn.net/weixin_34236497/article/details/90923511