-
-
Save tomaka/3469f733cd2506c4d31bd36a70a3cae7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 450 | |
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; | |
struct Neighbour { | |
int id; | |
float dist; | |
}; | |
struct TileDynamic { | |
float tax_money_in_delivery; | |
float population; | |
int dropout_direction; | |
float dist_nearest_primary_dropout; | |
float dist_nearest_secondary_dropout; | |
vec4 resources_stock[8]; | |
vec4 resources_flux[8]; | |
}; | |
struct TileRead { | |
vec2 position; | |
Neighbour neighbours[8]; | |
int controller_id; | |
float local_science_production; | |
int agriculture_request; | |
uint climate; | |
float terrain_penalty; | |
float infrastructure_level; | |
int num_primary_dropout; | |
int num_secondary_dropout; | |
vec4 resources_availability[8]; | |
}; | |
struct Nation { | |
vec3 rgb_color; | |
float money_per_population_per_tick; | |
}; | |
struct NationOut { | |
float taxes_money; | |
}; | |
layout(set = 0, binding = 0) readonly buffer TilesRead { | |
TileRead tiles[]; | |
}; | |
layout(set = 0, binding = 1) readonly buffer TilesIn { | |
TileDynamic tiles_in[]; | |
}; | |
layout(set = 0, binding = 2) buffer TilesOut { | |
TileDynamic tiles_out[]; | |
}; | |
layout(set = 0, binding = 3) readonly buffer NationsRead { | |
Nation nations[]; | |
}; | |
layout(set = 0, binding = 4) buffer NationsOut { | |
NationOut nations_out[]; | |
}; | |
void calculate_resource(uint tile_id) { | |
vec4 self_demand_weight[1]; | |
{ | |
int res_id = 0; | |
self_demand_weight[res_id] = 1.0 - exp(1.0 - tiles_in[tile_id].population / tiles_in[tile_id].resources_stock[res_id]); | |
self_demand_weight[res_id] *= 1.0 + 0.02 * log(2000.0 + tiles_in[tile_id].population); | |
tiles_out[tile_id].resources_stock[res_id] = tiles_in[tile_id].resources_stock[res_id]; | |
tiles_out[tile_id].resources_stock[res_id] += tiles_in[tile_id].population * 0.005; | |
} | |
{ | |
int i = 0; | |
Neighbour neighbour = tiles[tile_id].neighbours[i]; | |
if (neighbour.id == -1) return; | |
{ | |
int res_id = 0; | |
vec4 neighbour_stock = tiles_in[neighbour.id].resources_stock[res_id]; | |
float neighbour_pop = tiles_in[neighbour.id].population; | |
vec4 neighbour_demand_weight = 1.0 - exp(1.0 - neighbour_pop / neighbour_stock); | |
neighbour_demand_weight *= 1.0 + 0.02 * log(2000.0 + neighbour_pop); | |
vec4 transfer_from_neighbour = self_demand_weight[res_id] - neighbour_demand_weight; | |
vec4 transfer_quantity = mix(tiles_in[tile_id].resources_stock[res_id], neighbour_stock, step(0.0, transfer_from_neighbour)); | |
transfer_quantity *= transfer_from_neighbour; | |
transfer_quantity /= 8.0; | |
tiles_out[tile_id].resources_stock[res_id] += transfer_quantity; | |
} | |
} | |
} | |
void main() { | |
uint tile_id = gl_NumWorkGroups.x * gl_WorkGroupID.y + gl_WorkGroupID.x; | |
calculate_resource(tile_id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment