工作原理
對一個矩形區(qū)域操作
cpu下的代碼執(zhí)行方式:(依次執(zhí)行)
for x in range(width):
for y in range(height):
set_color(x, y, some_color)
gpu執(zhí)行方式: (并發(fā)執(zhí)行)
每個像素都會執(zhí)行一次這個函數(shù)
void fragment() {
COLOR = some_color;
}
gpu運算優(yōu)缺點
優(yōu)點:
- 位置頂點處理速度飛快
- 處理顏色速度飛快
- 處理光照效果速度飛快
- 可處理大量的數(shù)學計算
缺點:
- 不能網(wǎng)格外繪制
- 不能在當前像素/頂點下處理其他像素/頂點
- 不能存儲上一次效果
- 不能熱更新? (update on the fly (they can, but they need to be compiled))
結(jié)構(gòu)
godot下只有三個主函數(shù)vertex(), fragment(), light()
vertex()對每個網(wǎng)格上的頂點都進行處理
·fragment()·對每個像素處理
·light()·對光的反應進行處理