1 Star 4 Fork 1

董天泽/细胞大战

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
makemetaball.gdshader 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
shader_type canvas_item;
uniform sampler2D centerss;
uniform int cells;
/*
void fragment()
{
vec3 centers[100];
for (int i=0; i<centers.length(); i++)
{
centers[i] = vec3(0.0, 0.0, 0.0);
}
centers[1] = vec3(0.5, 0.25, 1.0);
centers[2] = vec3(0.7, 0.5, 1.0);
centers[3] = vec3(0.6, 0.8, 1.0);
COLOR = vec4(0.0, 0.0, 0.0, 1.0);
float influnce = 0.0;
for (int i=0; i<centers.length(); i++)
{
float distance_to_center = distance(centers[i].xy / TEXTURE_PIXEL_SIZE, UV / TEXTURE_PIXEL_SIZE);
influnce += (1.0 / distance_to_center) * centers[i].z;
}
if(influnce > 0.2)
{
COLOR = vec4(1.0);
}
else
{
COLOR = vec4(0.0);
}
}
*/
void fragment()
{
COLOR = vec4(0.0, 0.0, 0.0, 1.0);//init texture
vec4 centers[300];
for(int i=0; i<300; i++)
{
centers[i] = vec4(0.0);
}
for(int i=0; i<cells; i++)
{
centers[i] = vec4(texture(centerss, vec2(float(i)/300.0, 0.5)).r, texture(centerss, vec2(float(i)/300.0, 0.5)).g, texture(centerss, vec2(float(i)/300.0, 0.5)).b, 1.0);
}
int team = 0;
float influnce = 0.0;
for (int i=0; i<centers.length(); i++)
{
float distance_to_center = distance(centers[i].xy / TEXTURE_PIXEL_SIZE, UV / TEXTURE_PIXEL_SIZE);
influnce += (1.0 / distance_to_center) * centers[i].w;
if(centers[i].z > 0.5) team+=1;
else team -= 1;
}
if(influnce > 0.2)
{
if(team>0)
COLOR = vec4(1.0, 0.0, 0.0, 1.0);
else
COLOR = vec4(0.0, 0.0, 1.0, 1.0);
}
else
{
COLOR = vec4(0.0);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/brodong1205/cell-war.git
git@gitee.com:brodong1205/cell-war.git
brodong1205
cell-war
细胞大战
master

搜索帮助