改進粒子系統 動態編譯Shader

2021-06-16 00:26:38 字數 3221 閱讀 2429

改進粒子系統-動態編譯shader

動態決定需要編譯的

fx**

請教了幾個朋友,最後決定用使用fx支援的巨集定**決這個問題。

根據粒子使用的發射器和效果器定義不同的巨集,在fx檔案中通過判斷相應的巨集是否定義(#ifdef…#endif)來決定是否編譯某段**。

fx**如下:

struct vs_input ;

struct vs_output ;

matrix matworldviewproj;                        // world-view-proj matrix

float4 rightvector;                                // right vector

float4 upvector;                                // up vector

float4 time_colour;                                // elasped time, delta colour

float4 acceleration;       

float finitparticlewidth;

float finitparticleheight;

//texture textureparticle;

sampler particlesampler = sampler_state ;

#ifdef animationtexture

int        ianimtexsidelength;

int        ianimtexnumframe;

float    fanimtexduration;

#endif

#ifdef v3dscaleaffector

float fscalepersecond;

#endif

#ifdef v3dcolourimageaffector

texture texturecolour;

sampler coloursampler = sampler_state ;

#endif

vs_output vs(const vs_input input)

else if( input.tex1.x > 0.f)

if( input.tex1.y < 0.f)

else if( input.tex1.x > 0.f)

out.tex0 = fanimtexcorrdxy;

#endif

#ifdef v3dcolourimageaffector

out.tex1 = float2(flivetime, 0.f);

#endif

#ifdef v3drotationaffector

float frottexdatabase[8] = ;   

float frotation = input.tex3.x + flivetime * input.tex3.y;

float fsinrot, fcosrot;

sincos( frotation, fsinrot, fcosrot );

float2 frottexcorrdxy;

int irottexbaseidx = input.tex3.z*2;

frottexcorrdxy.x = (fcosrot * frottexdatabase[irottexbaseidx]) + (fsinrot * frottexdatabase[irottexbaseidx+1]) + 0.5;

frottexcorrdxy.y = (fsinrot * frottexdatabase[irottexbaseidx]) - (fcosrot * frottexdatabase[irottexbaseidx+1]) + 0.5;

out.tex0 = frottexcorrdxy;

#endif

return out; }

float4 ps_1_1( vs_output in ) : color0

technique tec0

} 對發射器,效果器的支援程度

shader渲染器支援的屬性

1, 預設高度

2, 預設寬度

3, 最大粒子數                    這裡代表同時存在的粒子數

4, 粒子朝向

5, 面向攝像機的方式

6, 粒子up向量          

7, 是否是2d粒子系統

支援所有發射器

8, 支援發射器特有屬性(如圓環發射器的內環大小,外環大小)

9, 角度

10, 起始顏色

11, 結束顏色

12, 方向

13, 最小生存期

14, 最大生存期

15, 最小速度

16, 最大速度

17, 位置

支援的效果器及屬性

18, 顏色衰減

19, 線性外力: "外力" 指加速度a, 滿足公式s = vt + 1/2*a*t*t, 受力模式不起作用

20, 旋轉

21, 縮放

22, 顏色衰減圖

不支援狀態無關的效果器:

1, 碰撞體

2, 隨機速度

3, 各種力場(直線力場,點力場)

專案改動

1, 對需要用gpu優化或需要使用gpu增強效果的粒子,美術編輯使用「shader渲染器」的版本。

2, shader渲染器實現版本的命名規則是在原有billboard渲染器的檔名後面加上 "_shader",程式通過檔名區分不同的版本。

3, 在遊戲中載入粒子的時候

if( (有gpu實現版本) && (顯示卡支援該粒子要求的vs、ps版本))

載入gpu實現版本

else

載入cpu實現版本

截圖

1, 旋轉

2, 縮放,此處可以看到大部分是顯示卡運算

3, 紋理動畫

todo

1, 解決粒子使用gpu處理和cpu處理的效果有些不同的問題

blog:

[email protected]

CCParticleSystem粒子系統

第一次接觸粒子系統,以前遊戲裡面的一些小特效,像製作動畫一樣,是採用一幀一幀的切出來的,由於這種特效,變化無常,切出來的幀,都非常的大,也很耗記憶體,一下就記憶體溢位了.呵呵 主要是以前都沒有接觸過.現在接觸了,以後遊戲就可以用到了.開心 建立乙個ccparticlesystem粒子系統 ccpar...

Unity粒子系統

首次接觸unity的粒子系統,內容太多,搞得都不好寫筆記,所以就記錄下unity的粒子系統做出來的東西以及經常用的一些引數。火焰效果製作 這個相對簡單 建立粒子系統物件 1 調duration 1 開啟loop start size 1 start lifetime 1 start speed 1 ...

Unity粒子系統

rateoverdistance 隨著移動距離產生的粒子數量。只有當粒子系統移動時,才發射粒子。bursts sprite 通過相同尺寸的sprite實現粒子動畫。tiles 網格的行列數。animation startframe 開始的幀是哪一幀。flipu 翻轉u。flipv 翻轉v。enabl...