Last active
April 7, 2016 09:24
-
-
Save tomaka/8c48cce3614e097eabd28e18cdb24965 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 science_delivery; | |
float taxes_delivery; | |
float science_points_per_tick; | |
float population; | |
float resources_stock[32]; | |
float resources_flux[32]; | |
}; | |
struct TileRead { | |
vec2 position; | |
Neighbour neighbours[8]; | |
uint is_dropout; | |
int owner_id; | |
int controller_id; | |
float local_science_production; | |
int agriculture_request; | |
uint climate; | |
float terrain_penalty; | |
float infrastructure_level; | |
float resources_availability[32]; | |
}; | |
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[]; | |
}; | |
void calculate_resource(uint tile_id, uint res_id) { | |
float self_demand_weight = 1.0 - exp(1.0 - tiles_in[tile_id].population / tiles_in[tile_id].resources_stock[res_id]); | |
self_demand_weight *= 1.0 + 0.02 * log(2000.0 + tiles_in[tile_id].population); | |
} | |
void main() { | |
uint tile_id = gl_NumWorkGroups.x * gl_WorkGroupID.y + gl_WorkGroupID.x; | |
if (tile_id >= tiles_out.length()) { return; } | |
//tiles_out[tile_id] = tiles_in[tile_id]; // FIXME: | |
// Calculating resources. | |
for (uint i = 0; i < 32; ++i) { | |
calculate_resource(tile_id, i); | |
} | |
// Calculating science production. | |
tiles_out[tile_id].science_points_per_tick = tiles[tile_id].local_science_production; | |
for (int i = 0; i < 8; ++i) { | |
float val = tiles_in[tiles[tile_id].neighbours[i].id].science_points_per_tick; | |
tiles_out[tile_id].science_points_per_tick = max(val, tiles_out[tile_id].science_points_per_tick); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment