From a0f78659f31abdce973bc6641b5b5a58f2ba9afc Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Mon, 16 Jun 2014 18:51:01 +0200 Subject: Improved faces shading with and without shaders. --- client/shaders/nodes_shader/opengl_fragment.glsl | 12 ------------ client/shaders/nodes_shader/opengl_vertex.glsl | 20 +++++++++++++------- .../water_surface_shader/opengl_fragment.glsl | 12 ------------ .../shaders/water_surface_shader/opengl_vertex.glsl | 20 +++++++++++++------- 4 files changed, 26 insertions(+), 38 deletions(-) (limited to 'client') diff --git a/client/shaders/nodes_shader/opengl_fragment.glsl b/client/shaders/nodes_shader/opengl_fragment.glsl index 351faf81b..2a1cbc568 100644 --- a/client/shaders/nodes_shader/opengl_fragment.glsl +++ b/client/shaders/nodes_shader/opengl_fragment.glsl @@ -99,12 +99,6 @@ vec4 base = texture2D(baseTexture, uv).rgba; float alpha = gl_Color.a; vec4 col = vec4(color.rgb, alpha); col *= gl_Color; - col = col * col; // SRGB -> Linear - col *= 1.8; - col.r = 1.0 - exp(1.0 - col.r) / e; - col.g = 1.0 - exp(1.0 - col.g) / e; - col.b = 1.0 - exp(1.0 - col.b) / e; - col = sqrt(col); // Linear -> SRGB if(fogDistance != 0.0){ float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0)); alpha = mix(alpha, 0.0, d); @@ -113,12 +107,6 @@ vec4 base = texture2D(baseTexture, uv).rgba; #else vec4 col = vec4(color.rgb, base.a); col *= gl_Color; - col = col * col; // SRGB -> Linear - col *= 1.8; - col.r = 1.0 - exp(1.0 - col.r) / e; - col.g = 1.0 - exp(1.0 - col.g) / e; - col.b = 1.0 - exp(1.0 - col.b) / e; - col = sqrt(col); // Linear -> SRGB if(fogDistance != 0.0){ float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0)); col = mix(col, skyBgColor, d); diff --git a/client/shaders/nodes_shader/opengl_vertex.glsl b/client/shaders/nodes_shader/opengl_vertex.glsl index b09d03774..88e489e6c 100644 --- a/client/shaders/nodes_shader/opengl_vertex.glsl +++ b/client/shaders/nodes_shader/opengl_vertex.glsl @@ -63,28 +63,35 @@ void main(void) vec3 normal, tangent, binormal; normal = normalize(gl_NormalMatrix * gl_Normal); + float tileContrast = 1.0; if (gl_Normal.x > 0.5) { // 1.0, 0.0, 0.0 + tileContrast = 0.8; tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, -1.0)); binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0)); } else if (gl_Normal.x < -0.5) { // -1.0, 0.0, 0.0 + tileContrast = 0.8; tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0)); binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0)); } else if (gl_Normal.y > 0.5) { // 0.0, 1.0, 0.0 + tileContrast = 1.2; tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0)); binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0)); } else if (gl_Normal.y < -0.5) { // 0.0, -1.0, 0.0 + tileContrast = 0.3; tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0)); binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0)); } else if (gl_Normal.z > 0.5) { // 0.0, 0.0, 1.0 + tileContrast = 0.5; tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0)); binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0)); } else if (gl_Normal.z < -0.5) { // 0.0, 0.0, -1.0 + tileContrast = 0.5; tangent = normalize(gl_NormalMatrix * vec3(-1.0, 0.0, 0.0)); binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0)); } @@ -108,7 +115,7 @@ void main(void) // Moonlight is blue b += (day - night) / 13.0; - rg -= (day - night) / 23.0; + rg -= (day - night) / 13.0; // Emphase blue a bit in darker places // See C++ implementation in mapblock_mesh.cpp finalColorBlend() @@ -118,18 +125,17 @@ void main(void) // See C++ implementation in mapblock_mesh.cpp finalColorBlend() rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065); - color.r = clamp(rg,0.0,1.0); - color.g = clamp(rg,0.0,1.0); - color.b = clamp(b,0.0,1.0); + color.r = rg; + color.g = rg; + color.b = b; #if !(MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE) // Make sides and bottom darker than the top color = color * color; // SRGB -> Linear - if(gl_Normal.y <= 0.5) - color *= 0.6; + color *= tileContrast; color = sqrt(color); // Linear -> SRGB #endif color.a = gl_Color.a; - gl_FrontColor = gl_BackColor = color; + gl_FrontColor = gl_BackColor = clamp(color,0.0,1.0); } diff --git a/client/shaders/water_surface_shader/opengl_fragment.glsl b/client/shaders/water_surface_shader/opengl_fragment.glsl index 351faf81b..2a1cbc568 100644 --- a/client/shaders/water_surface_shader/opengl_fragment.glsl +++ b/client/shaders/water_surface_shader/opengl_fragment.glsl @@ -99,12 +99,6 @@ vec4 base = texture2D(baseTexture, uv).rgba; float alpha = gl_Color.a; vec4 col = vec4(color.rgb, alpha); col *= gl_Color; - col = col * col; // SRGB -> Linear - col *= 1.8; - col.r = 1.0 - exp(1.0 - col.r) / e; - col.g = 1.0 - exp(1.0 - col.g) / e; - col.b = 1.0 - exp(1.0 - col.b) / e; - col = sqrt(col); // Linear -> SRGB if(fogDistance != 0.0){ float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0)); alpha = mix(alpha, 0.0, d); @@ -113,12 +107,6 @@ vec4 base = texture2D(baseTexture, uv).rgba; #else vec4 col = vec4(color.rgb, base.a); col *= gl_Color; - col = col * col; // SRGB -> Linear - col *= 1.8; - col.r = 1.0 - exp(1.0 - col.r) / e; - col.g = 1.0 - exp(1.0 - col.g) / e; - col.b = 1.0 - exp(1.0 - col.b) / e; - col = sqrt(col); // Linear -> SRGB if(fogDistance != 0.0){ float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0)); col = mix(col, skyBgColor, d); diff --git a/client/shaders/water_surface_shader/opengl_vertex.glsl b/client/shaders/water_surface_shader/opengl_vertex.glsl index b09d03774..88e489e6c 100644 --- a/client/shaders/water_surface_shader/opengl_vertex.glsl +++ b/client/shaders/water_surface_shader/opengl_vertex.glsl @@ -63,28 +63,35 @@ void main(void) vec3 normal, tangent, binormal; normal = normalize(gl_NormalMatrix * gl_Normal); + float tileContrast = 1.0; if (gl_Normal.x > 0.5) { // 1.0, 0.0, 0.0 + tileContrast = 0.8; tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, -1.0)); binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0)); } else if (gl_Normal.x < -0.5) { // -1.0, 0.0, 0.0 + tileContrast = 0.8; tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0)); binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0)); } else if (gl_Normal.y > 0.5) { // 0.0, 1.0, 0.0 + tileContrast = 1.2; tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0)); binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0)); } else if (gl_Normal.y < -0.5) { // 0.0, -1.0, 0.0 + tileContrast = 0.3; tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0)); binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0)); } else if (gl_Normal.z > 0.5) { // 0.0, 0.0, 1.0 + tileContrast = 0.5; tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0)); binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0)); } else if (gl_Normal.z < -0.5) { // 0.0, 0.0, -1.0 + tileContrast = 0.5; tangent = normalize(gl_NormalMatrix * vec3(-1.0, 0.0, 0.0)); binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0)); } @@ -108,7 +115,7 @@ void main(void) // Moonlight is blue b += (day - night) / 13.0; - rg -= (day - night) / 23.0; + rg -= (day - night) / 13.0; // Emphase blue a bit in darker places // See C++ implementation in mapblock_mesh.cpp finalColorBlend() @@ -118,18 +125,17 @@ void main(void) // See C++ implementation in mapblock_mesh.cpp finalColorBlend() rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065); - color.r = clamp(rg,0.0,1.0); - color.g = clamp(rg,0.0,1.0); - color.b = clamp(b,0.0,1.0); + color.r = rg; + color.g = rg; + color.b = b; #if !(MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE) // Make sides and bottom darker than the top color = color * color; // SRGB -> Linear - if(gl_Normal.y <= 0.5) - color *= 0.6; + color *= tileContrast; color = sqrt(color); // Linear -> SRGB #endif color.a = gl_Color.a; - gl_FrontColor = gl_BackColor = color; + gl_FrontColor = gl_BackColor = clamp(color,0.0,1.0); } -- cgit v1.2.3