UE4 非debug方式繪製line

2021-10-25 03:58:46 字數 2292 閱讀 4303

在ue中,我們可以使用drawdebugline的方式在世界上繪製直線,或者使用相關的一些介面來繪製長方體、球體等,但是當遊戲發布後,這種debug型別的繪製內容一般會被優化掉,不會在遊戲世界中顯示。

在這裡我們使用另一種方法來繪製,使得遊戲在非debug狀態下也可以繪製線段。

在這裡首先定義乙個ulinebatchcomponent型別的指標:

ulinebatchcomponent* const linebatchcomponent = getworld()->persistentlinebatcher;

我們利用這一變數進行繪製,為了更快的批量繪製線段,我們需要定義乙個fbatchline型別的tarray,儲存我們要繪製的線段,每條線段均為fbatchline型別,程式如下:

tarraylines;

flinearcolor color = flinearcolor(0, 0, 0, 1);

float lifetime = 0;

float thickness = 1;

uint8 depth = 0;

fbatchedline line = fbatchedline(pointleftbottomfront, pointrightbottomfront, color, lifetime, thickness, depth);

lines.add(line);

line = fbatchedline(pointleftbottomfront, pointleftbottomback, color, lifetime, thickness, depth);

lines.add(line);

line = fbatchedline(pointleftbottomfront, pointlefttopfront, color, lifetime, thickness, depth);

lines.add(line);

line = fbatchedline(pointlefttopfront, pointlefttopback, color, lifetime, thickness, depth);

lines.add(line);

line = fbatchedline(pointlefttopfront, pointrighttopfront, color, lifetime, thickness, depth);

lines.add(line);

line = fbatchedline(pointlefttopback, pointrighttopback, color, lifetime, thickness, depth);

lines.add(line);

line = fbatchedline(pointleftbottomback, pointrightbottomback, color, lifetime, thickness, depth);

lines.add(line);

line = fbatchedline(pointleftbottomback, pointlefttopback, color, lifetime, thickness, depth);

lines.add(line);

line = fbatchedline(pointrightbottomfront, pointrighttopfront, color, lifetime, thickness, depth);

lines.add(line);

line = fbatchedline(pointrightbottomfront, pointrightbottomback, color, lifetime, thickness, depth);

lines.add(line);

line = fbatchedline(pointrighttopfront, pointrighttopback, color, lifetime, thickness, depth);

lines.add(line);

line = fbatchedline(pointrighttopback, pointrightbottomback, color, lifetime, thickness, depth);

lines.add(line);

其中point******均為fvector型別,表示line的起點和終點,其他引數從命名上就能看出來含義,具體型別可以檢視ue官方文件。將所有line儲存在tarray型別的lines變數中後,呼叫函式:

linebatchcomponent->drawlines(lines);

將lines陣列傳入,就可以在遊戲場景中繪製出指定線段了。

UE4學習記錄 Debug工具

件 debugtool.h 宣告log類別 declare log category extern logdebug,log,all 類似std cout的用法,過載 運算子實現debug列印,整合螢幕列印和log列印 class fdebugtool 根據pattern輸出debug資訊 void...

UE4 虛幻引擎,預設渲染方式 PBR

預設情況下,虛幻引擎使用基於物理的渲染管線,即pbr 基於物理的渲染 管線,該管線將基於物理的材質與基於物理的光照相結合,以實現盡可能真實的渲染效果作為預設環境。預設情況下,虛幻引擎使用延遲渲染器,它會輸出每個材質的gbuffer即基礎顏色 金屬 粗糙度等,也就是所謂的 渲染目標 合成器 使用緩衝資...

UE4頂點繪製材質節點連線筆記

使用到的材質節點 線性差值節點,alpha連線你需要使用的通道 使用vertex color節點 ab就是連線拿來頂點繪製的貼圖,如果需要3個以上貼圖使用節點往後疊加連線就可以,例 比如如果需要讓草地根據磚縫繪製,把上面的線性差值節點換成這個就可以,但是需要一張高度圖連線節點上對應的介面 第四個he...