Godot - 粒子Shader

粒子shader 其实是用shader来写粒子的参数效果,用起来过于复杂,这里只贴一个简单随机向四周扩散的粒子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);
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容