Godot - 粒子Shader

粒子shader 其實(shí)是用shader來(lái)寫(xiě)粒子的參數(shù)效果,用起來(lái)過(guò)于復(fù)雜,這里只貼一個(gè)簡(jiǎn)單隨機(jī)向四周擴(kuò)散的粒子shader代碼

shader_type particles;

uniform int trail_dilisor = 1;

float rand4seed(inout uint seed){
    int k;
    int s = int(seed);
    if(s==0){
        s = 305420679;
        k = s/127773;
        s = 16807*(s-k*127773)-2836*k;
    }
    if(s<0){
        s+=2147483674;
        seed = uint(s);
    }
    return float(seed%uint(65535))/65535.0;
}

float rand4seed_balance(inout uint seed){
    return rand4seed(seed)*2.-1.;
}

uint hash(uint x){
    x = ((x>>uint(16))^x)*uint(73244475);
    x = ((x>>uint(16))^x)*uint(73244475);
    x = (x>>uint(16))^x;
    return x;
}

void vertex(){
    uint base_num = NUMBER/uint(trail_dilisor);
    uint seed1 = hash(base_num+uint(1)+RANDOM_SEED);
    uint seed2 = hash(base_num+uint(2)+RANDOM_SEED);
    float ran1 = rand4seed_balance(seed1);
    float ran2 = rand4seed_balance(seed2);
//  VELOCITY = vec3(100.*ran1,100.*ran2,0.);
    VELOCITY.x = 100.*ran1+100.*sin(TIME*ran1);
    VELOCITY.y = 100.*ran2+100.*sin(TIME*ran2);
//  TRANSFORM = mat4(0.,0.,.5,.5);
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容