Skip to content

Commit

Permalink
Merge pull request #1810 from ineveraskedforthis/main
Browse files Browse the repository at this point in the history
Graphical changes.
  • Loading branch information
schombert authored Dec 1, 2024
2 parents df59d54 + 2fb6344 commit 7cf93c1
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 81 deletions.
61 changes: 51 additions & 10 deletions assets/shaders/glsl/text_line_f.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,37 @@ vec4 gamma_correct(vec4 colour) {
return vec4(pow(colour.rgb, vec3(1.f / gamma)), colour.a);
}


float clamp(float x, float lowerlimit, float upperlimit) {
if (x < lowerlimit) return lowerlimit;
if (x > upperlimit) return upperlimit;
return x;
}

float smoothstep (float edge0, float edge1, float x) {
x = clamp((x - edge0) / (edge1 - edge0), 0.1f, 1.f);

return x * x * (3.0f - 2.0f * x);
}


float get_value(float d) {
float value = 1.f;
if (d > 0.5f) {
return 0.f;
} else if ((d > 0.500f) && (d < 0.510f)) {
value = 1.f - smoothstep(0.500f, 0.510f, d);
} else {
value = 1.f;
}
return value;
}

float get_opacity(float d) {
float t = max(0.0f, d * 16.0f - 7.0f);
return pow(t, 5.f);
}

void main() {
float border_size = 0.022f;
vec3 inner_color = vec3(1.0 - is_black, 1.0 - is_black, 1.0 - is_black);
Expand All @@ -20,15 +51,25 @@ void main() {
outer_color = mix(inner_color, outer_color, text_size * 40.f);

vec4 color_in = texture(texture_sampler, vec2(tex_coord.rg));
if(color_in.r > 0.5) {
frag_color = vec4(inner_color, 1.0f);
} else if(color_in.r > 0.495) {
frag_color = vec4(mix(inner_color, outer_color, 1.0f - (color_in.r - 0.5f) * 200.0f), 1.0f);
} else {
float t = max(0.0f, color_in.r * 16.0f - 7.0f);
frag_color = vec4(outer_color, pow(t, 5.f));
}

frag_color.a *= opacity;

float dist = color_in.r;
vec2 ddist = vec2(dFdx(dist), dFdy(dist));
float pixel_distance = length(ddist) * 0.1f;

float average_value = 0.f;
for (int i = -5; i <= 5; i++) {
average_value += get_value(dist + i * pixel_distance);
}

float average_opacity = 0.f;
for (int i = -5; i <= 5; i++) {
average_opacity += get_opacity(dist + i * pixel_distance);
}

average_value /= 11.f;
average_opacity /= 11.f;


frag_color = vec4(mix(inner_color, outer_color, average_value), average_opacity * opacity);
frag_color = gamma_correct(frag_color);
}
4 changes: 2 additions & 2 deletions src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ void display_data::render(sys::state& state, glm::vec2 screen_size, glm::vec2 of

//glMultiDrawArrays(GL_TRIANGLE_STRIP, coastal_starts.data(), coastal_counts.data(), GLsizei(coastal_starts.size()));

// impassible borders
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[texture_provinces]);
glActiveTexture(GL_TEXTURE1);
Expand All @@ -624,8 +623,9 @@ void display_data::render(sys::state& state, glm::vec2 screen_size, glm::vec2 of
}
}
}
// impassible borders
{
glUniform1f(shader_uniforms[shader_borders][uniform_width], 0.00085f); // width
glUniform1f(shader_uniforms[shader_borders][uniform_width], 0.0004f); // width
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, textures[texture_imp_border]);
for(auto b : borders) {
Expand Down
Loading

0 comments on commit 7cf93c1

Please sign in to comment.