#version 460 in vec2 coord; uniform bool preview_colormap; uniform uvec2 dimensions; uniform uint show_max_age; uniform uint global_max_age; uniform uint global_minimum_max_age; uniform float blend_step; uniform vec3 dead_color; uniform bool dead_color_is_cielab; uniform vec3 living_color; uniform sampler1D living_colormap; uniform bool living_use_colormap; uniform bool living_colormap_invert; uniform uint living_colormap_scale; uniform bool living_colormap_scale_is_max_age; uniform bool living_color_is_cielab; out vec3 color; layout (std430) restrict readonly buffer buffer_data_from { uint data_from[]; }; layout (std430) restrict readonly buffer buffer_data_to { uint data_to[]; }; #include "cellstate_common.glsl" #include "color_conversion.glsl" vec3 blend_color(vec3 from, vec3 to, float step) { return vec3( from.x * (1. - step) + to.x * step, from.y * (1. - step) + to.y * step, from.z * (1. - step) + to.z * step ); } // TODO: support cielab, cieluv and oklab? vec3 get_color(CellState state, uint living_colormap_scale_) { vec3 color; if (state.alive) { if (living_use_colormap) { float pos = float(state.age) / float(living_colormap_scale_); if (living_colormap_invert) { pos = 1. - pos; } return texture(living_colormap, pos).rgb; } else { return living_color; } } else { return dead_color; } } void main() { uint x = uint(float(dimensions.x) * (coord.x + 1.) / 2.); uint y = uint(float(dimensions.y) * (coord.y + 1.) / 2.); uint pos = x + y * dimensions.x; uint max_age = data_from[dimensions.x * dimensions.y + pos]; float max_age_val = float(max_age - global_minimum_max_age) / float(global_max_age); CellState state_from = cellstate_from_data(data_from[pos]); CellState state_to = cellstate_from_data(data_to[pos]); uint living_colormap_scale_from; uint living_colormap_scale_to; if (living_colormap_scale_is_max_age) { living_colormap_scale_from = data_from[dimensions.x * dimensions.y + pos]; living_colormap_scale_to = data_to[dimensions.x * dimensions.y + pos]; } else { living_colormap_scale_from = living_colormap_scale; living_colormap_scale_to = living_colormap_scale; } vec3 color_from = get_color(state_from, living_colormap_scale_from); vec3 color_to = get_color(state_to, living_colormap_scale_to); vec3 color_lab = blend_color(color_from, color_to, blend_step); vec3 color_rgb = convert_cielab_to_rgb(color_lab); if (show_max_age == 0) { color = color_rgb; } else if (show_max_age == 1) { color = vec3(max_age_val,max_age_val,max_age_val); } else if (show_max_age == 2) { float r = color_rgb.r * .1 + max_age_val * .9; float g = color_rgb.g * .1 + max_age_val * .9; float b = color_rgb.b * .1 + max_age_val * .9; color = vec3(r,g,b); } if (preview_colormap) { color = convert_cielab_to_rgb(texture(living_colormap, (coord.x+1.)/2.).rgb); } } //void main(){ //// color = texture(living_colormap, (coord.x+1.)/2.).rgb; // color = convert_cielab_to_rgb(texture(living_colormap, (coord.x+1.)/2.).rgb); //}