factory-expansion/logic/world/chunk/chunk.gdshader

50 lines
1.5 KiB
Plaintext

shader_type canvas_item;
uniform float tile_count;
const int chunk_size = 32;
uniform bool borders = true;
const float border_size = 0.01;
uniform int tiles[chunk_size*chunk_size];
uniform int items[chunk_size*chunk_size];
uniform int arrows[chunk_size*chunk_size];
uniform sampler2DArray tile_texture : filter_nearest_mipmap;
uniform sampler2DArray item_texture : filter_nearest;
uniform sampler2DArray arrow_texture : filter_nearest;
void fragment() {
COLOR = vec4(0,0,0,0);
int arrow_id = arrows[int(floor(float(chunk_size) * UV.x) + float(chunk_size) * floor(float(chunk_size) * UV.y))];
if (arrow_id != -1){
COLOR = texture(arrow_texture,
vec3(mod(UV.x * float(chunk_size), 1.0), mod(UV.y * float(chunk_size), 1.0), float(arrow_id)) // map
);
}
if (COLOR == vec4(0,0,0,0)){
int item_id = items[int(floor(float(chunk_size) * UV.x) + float(chunk_size) * floor(float(chunk_size) * UV.y))];
if (item_id != -1){
COLOR = texture(item_texture,
vec3(mod(UV.x * float(chunk_size), 1.0), mod(UV.y * float(chunk_size), 1.0), float(item_id)) // map
);
}
}
if (COLOR == vec4(0,0,0,0)){
int tile_id = tiles[int(floor(float(chunk_size) * UV.x) + float(chunk_size) * floor(float(chunk_size) * UV.y))];
COLOR = texture(tile_texture,
vec3(mod(UV.x * float(chunk_size), 1.0), mod(UV.y * float(chunk_size), 1.0), float(tile_id)) // map
);
}
if (borders){
if(
UV.x < border_size || UV.x > 1.0-border_size ||
UV.y < border_size || UV.y > 1.0-border_size
){
COLOR -= vec4(0.1,0.1,0.1,0);
}
}
}