diff --git a/res/shaders/background.glslf b/res/shaders/background.glslf index 466372c9..f7ff07c8 100644 --- a/res/shaders/background.glslf +++ b/res/shaders/background.glslf @@ -4,6 +4,6 @@ out vec4 f_color; uniform samplerCube u_cubemap; void main(){ - vec3 dir = normalize(v_coord); - f_color = texture(u_cubemap, dir); + vec3 dir = normalize(v_coord); + f_color = texture(u_cubemap, dir); } diff --git a/res/shaders/background.glslv b/res/shaders/background.glslv index 1370e400..4de0d5b8 100644 --- a/res/shaders/background.glslv +++ b/res/shaders/background.glslv @@ -7,6 +7,6 @@ uniform float u_ar; uniform float u_zoom; void main(){ - v_coord = (vec4(v_position*vec2(u_ar, 1.0f)*u_zoom, -1.0, 1.0) * u_view).xyz; - gl_Position = vec4(v_position, 0.0, 1.0); + v_coord = (vec4(v_position*vec2(u_ar, 1.0f)*u_zoom, -1.0, 1.0) * u_view).xyz; + gl_Position = vec4(v_position, 0.0, 1.0); } diff --git a/res/shaders/lib/commons.glsl b/res/shaders/lib/commons.glsl index f2f1b3bc..0a694422 100644 --- a/res/shaders/lib/commons.glsl +++ b/res/shaders/lib/commons.glsl @@ -1,12 +1,27 @@ +#ifndef COMMONS_GLSL_ +#define COMMONS_GLSL_ + +#include + #define PI 3.1415926535897932384626433832795 #define PI2 (PI*2) vec4 decompress_light(float compressed_light) { - vec4 result; + vec4 result; int compressed = floatBitsToInt(compressed_light); result.r = ((compressed >> 24) & 0xFF) / 255.f; result.g = ((compressed >> 16) & 0xFF) / 255.f; result.b = ((compressed >> 8) & 0xFF) / 255.f; result.a = (compressed & 0xFF) / 255.f; - return result; + return result; } + +vec3 pick_sky_color(samplerCube cubemap) { + vec3 skyLightColor = texture(cubemap, vec3(0.4f, 0.0f, 0.4f)).rgb; + skyLightColor *= SKY_LIGHT_TINT; + skyLightColor = min(vec3(1.0), skyLightColor*SKY_LIGHT_MUL); + skyLightColor = max(MAX_SKY_LIGHT, skyLightColor); + return skyLightColor; +} + +#endif // COMMONS_GLSL_ diff --git a/res/shaders/lib/constants.glsl b/res/shaders/lib/constants.glsl new file mode 100644 index 00000000..161a505b --- /dev/null +++ b/res/shaders/lib/constants.glsl @@ -0,0 +1,15 @@ +#ifndef CONSTANTS_GLSL_ +#define CONSTANTS_GLSL_ + +// geometry +#define CURVATURE_FACTOR 0.002 + +// lighting +#define SKY_LIGHT_MUL 2.5 +#define SKY_LIGHT_TINT vec3(0.9, 0.8, 1.0) +#define MAX_SKY_LIGHT vec3(0.1, 0.11, 0.14) + +// fog +#define FOG_POS_SCALE vec3(1.0, 0.2, 1.0) + +#endif // CONSTANTS_GLSL_ diff --git a/res/shaders/lines.glslf b/res/shaders/lines.glslf index e5e415e8..61258235 100644 --- a/res/shaders/lines.glslf +++ b/res/shaders/lines.glslf @@ -2,5 +2,5 @@ in vec4 v_color; out vec4 f_color; void main(){ - f_color = v_color; + f_color = v_color; } diff --git a/res/shaders/lines.glslv b/res/shaders/lines.glslv index 649f3f87..3fcd2fe4 100644 --- a/res/shaders/lines.glslv +++ b/res/shaders/lines.glslv @@ -6,6 +6,6 @@ out vec4 v_color; uniform mat4 u_projview; void main(){ - v_color = a_color; - gl_Position = u_projview * vec4(a_position, 1.0); + v_color = a_color; + gl_Position = u_projview * vec4(a_position, 1.0); } diff --git a/res/shaders/main.glslf b/res/shaders/main.glslf index 97e49cfb..071c56b3 100644 --- a/res/shaders/main.glslf +++ b/res/shaders/main.glslf @@ -11,13 +11,14 @@ uniform float u_fogFactor; uniform float u_fogCurve; void main(){ - vec3 fogColor = texture(u_cubemap, a_dir).rgb; - vec4 tex_color = texture(u_texture0, a_texCoord); - float depth = (a_distance/256.0); - float alpha = a_color.a * tex_color.a; - // anyway it's any alpha-test alternative required - if (alpha < 0.3f) - discard; - f_color = mix(a_color * tex_color, vec4(fogColor,1.0), min(1.0, pow(depth*u_fogFactor, u_fogCurve))); - f_color.a = alpha; + vec3 fogColor = texture(u_cubemap, a_dir).rgb; + vec4 tex_color = texture(u_texture0, a_texCoord); + float depth = (a_distance/256.0); + float alpha = a_color.a * tex_color.a; + // anyway it's any alpha-test alternative required + if (alpha < 0.3f) + discard; + f_color = mix(a_color * tex_color, vec4(fogColor,1.0), + min(1.0, pow(depth*u_fogFactor, u_fogCurve))); + f_color.a = alpha; } diff --git a/res/shaders/main.glslv b/res/shaders/main.glslv index e59839a0..90b0d82f 100644 --- a/res/shaders/main.glslv +++ b/res/shaders/main.glslv @@ -20,29 +20,22 @@ uniform samplerCube u_cubemap; uniform vec3 u_torchlightColor; uniform float u_torchlightDistance; -#define SKY_LIGHT_MUL 2.5 - - void main(){ - vec3 pos3d = (u_model * vec4(v_position, 1.0)).xyz-u_cameraPos.xyz; - vec4 modelpos = u_model * vec4(v_position, 1.0); - modelpos.y -= pow(length(pos3d.xz)*0.002, 3.0); - vec4 viewmodelpos = u_view * modelpos; - vec4 decomp_light = decompress_light(v_light); - vec3 light = decomp_light.rgb; - float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz)/u_torchlightDistance); - a_dir = modelpos.xyz - u_cameraPos; - light += torchlight * u_torchlightColor; - a_color = vec4(pow(light, vec3(u_gamma)),1.0f); - a_texCoord = v_texCoord; + vec4 modelpos = u_model * vec4(v_position, 1.0); + vec3 pos3d = modelpos.xyz-u_cameraPos.xyz; + modelpos.y -= pow(length(pos3d.xz)*CURVATURE_FACTOR, 3.0); + vec4 viewmodelpos = u_view * modelpos; + vec4 decomp_light = decompress_light(v_light); + + vec3 light = decomp_light.rgb; + float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz)/u_torchlightDistance); + light += torchlight * u_torchlightColor; + a_color = vec4(pow(light, vec3(u_gamma)),1.0f); + a_texCoord = v_texCoord; - vec3 skyLightColor = texture(u_cubemap, vec3(0.4f, 0.0f, 0.4f)).rgb; - skyLightColor.g *= 0.9; - skyLightColor.b *= 0.8; - skyLightColor = min(vec3(1.0), skyLightColor*SKY_LIGHT_MUL); - skyLightColor = max(vec3(0.1, 0.11, 0.14), skyLightColor); - - a_color.rgb = max(a_color.rgb, skyLightColor.rgb*decomp_light.a); - a_distance = length(u_view * u_model * vec4(pos3d.x, pos3d.y*0.2, pos3d.z, 0.0)); - gl_Position = u_proj * viewmodelpos; + a_dir = modelpos.xyz - u_cameraPos; + vec3 skyLightColor = pick_sky_color(u_cubemap); + a_color.rgb = max(a_color.rgb, skyLightColor.rgb*decomp_light.a); + a_distance = length(u_view * u_model * vec4(pos3d * FOG_POS_SCALE, 0.0)); + gl_Position = u_proj * viewmodelpos; } diff --git a/res/shaders/screen.glslf b/res/shaders/screen.glslf index 00041cbc..e7523d10 100644 --- a/res/shaders/screen.glslf +++ b/res/shaders/screen.glslf @@ -19,7 +19,7 @@ vec4 apply_vignette(vec4 color) { } void main() { - f_color = texture(u_texture0, v_coord); - f_color = apply_vignette(f_color); + f_color = texture(u_texture0, v_coord); + f_color = apply_vignette(f_color); } diff --git a/res/shaders/screen.glslv b/res/shaders/screen.glslv index b319c53f..593e5f19 100644 --- a/res/shaders/screen.glslv +++ b/res/shaders/screen.glslv @@ -7,7 +7,7 @@ uniform float u_timer; uniform float u_dayTime; void main(){ - v_coord = v_position * 0.5 + 0.5; - gl_Position = vec4(v_position, 0.0, 1.0); + v_coord = v_position * 0.5 + 0.5; + gl_Position = vec4(v_position, 0.0, 1.0); } diff --git a/res/shaders/skybox_gen.glslf b/res/shaders/skybox_gen.glslf index 27c8f567..b63ae0ee 100644 --- a/res/shaders/skybox_gen.glslf +++ b/res/shaders/skybox_gen.glslf @@ -43,7 +43,7 @@ SOFTWARE. #define LIGHT_STEPS 4 vec3 calculate_scattering( - vec3 start, // the start of the ray (the camera position) + vec3 start, // the start of the ray (the camera position) vec3 dir, // the direction of the ray (the camera vector) float max_dist, // the maximum distance the ray can travel (because something is in the way, like an object) vec3 scene_color, // the color of the scene @@ -201,16 +201,16 @@ vec3 calculate_scattering( // and increment the position on this ray ray_pos_i += step_size_i; - + } // calculate how much light can pass through the atmosphere vec3 opacity = exp(-(beta_mie * opt_i.y + beta_ray * opt_i.x + beta_absorption * opt_i.z)); - // calculate and return the final color + // calculate and return the final color return ( - phase_ray * beta_ray * total_ray // rayleigh color - + phase_mie * beta_mie * total_mie // mie + phase_ray * beta_ray * total_ray // rayleigh color + + phase_mie * beta_mie * total_mie // mie + opt_i.x * beta_ambient // and ambient ) * light_intensity + scene_color * opacity; // now make sure the background is rendered correctly } @@ -264,7 +264,7 @@ void main() { vec3 col = vec3(0.0);//scene.xyz; // get the atmosphere color col += calculate_scattering( - camera_position, // the position of the camera + camera_position, // the position of the camera camera_vector, // the camera vector (ray direction of this pixel) 1e12f, // max dist, essentially the scene depth vec3(0.0f), // scene color, the color of the current pixel being rendered diff --git a/res/shaders/skybox_gen.glslv b/res/shaders/skybox_gen.glslv index fdd0667c..bd6981ce 100644 --- a/res/shaders/skybox_gen.glslv +++ b/res/shaders/skybox_gen.glslv @@ -3,6 +3,6 @@ layout (location = 0) in vec2 v_position; out vec2 v_coord; void main(){ - v_coord = v_position; - gl_Position = vec4(v_position, 0.0, 1.0); + v_coord = v_position; + gl_Position = vec4(v_position, 0.0, 1.0); } diff --git a/res/shaders/ui.glslf b/res/shaders/ui.glslf index 2e189a81..4d040068 100644 --- a/res/shaders/ui.glslf +++ b/res/shaders/ui.glslf @@ -5,5 +5,5 @@ out vec4 f_color; uniform sampler2D u_texture; void main(){ - f_color = a_color * texture(u_texture, a_textureCoord); + f_color = a_color * texture(u_texture, a_textureCoord); } diff --git a/res/shaders/ui.glslv b/res/shaders/ui.glslv index d567e05d..eace7d38 100644 --- a/res/shaders/ui.glslv +++ b/res/shaders/ui.glslv @@ -8,7 +8,7 @@ out vec4 a_color; uniform mat4 u_projview; void main(){ - a_textureCoord = v_textureCoord; - a_color = v_color; - gl_Position = u_projview * vec4(v_position, 0.5, 1.0); + a_textureCoord = v_textureCoord; + a_color = v_color; + gl_Position = u_projview * vec4(v_position, 0.5, 1.0); } diff --git a/res/shaders/ui3d.glslf b/res/shaders/ui3d.glslf index 5b2fc4fd..550a5e94 100644 --- a/res/shaders/ui3d.glslf +++ b/res/shaders/ui3d.glslf @@ -5,6 +5,6 @@ out vec4 f_color; uniform sampler2D u_texture; void main(){ - f_color = a_color * texture(u_texture, a_textureCoord); + f_color = a_color * texture(u_texture, a_textureCoord); if (f_color.a == 0.0) discard; } diff --git a/res/shaders/ui3d.glslv b/res/shaders/ui3d.glslv index 65ccf0df..e9541419 100644 --- a/res/shaders/ui3d.glslv +++ b/res/shaders/ui3d.glslv @@ -9,7 +9,7 @@ uniform mat4 u_projview; uniform mat4 u_apply; void main(){ - a_textureCoord = v_textureCoord; - a_color = v_color; - gl_Position = u_apply * u_projview * vec4(v_position, 1.0); + a_textureCoord = v_textureCoord; + a_color = v_color; + gl_Position = u_apply * u_projview * vec4(v_position, 1.0); }