Skip to content

Commit a0f7865

Browse files
committedJun 16, 2014
Improved faces shading with and without shaders.
1 parent 9f46cb6 commit a0f7865

File tree

5 files changed

+52
-45
lines changed

5 files changed

+52
-45
lines changed
 

‎client/shaders/nodes_shader/opengl_fragment.glsl

-12
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,6 @@ vec4 base = texture2D(baseTexture, uv).rgba;
9999
float alpha = gl_Color.a;
100100
vec4 col = vec4(color.rgb, alpha);
101101
col *= gl_Color;
102-
col = col * col; // SRGB -> Linear
103-
col *= 1.8;
104-
col.r = 1.0 - exp(1.0 - col.r) / e;
105-
col.g = 1.0 - exp(1.0 - col.g) / e;
106-
col.b = 1.0 - exp(1.0 - col.b) / e;
107-
col = sqrt(col); // Linear -> SRGB
108102
if(fogDistance != 0.0){
109103
float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
110104
alpha = mix(alpha, 0.0, d);
@@ -113,12 +107,6 @@ vec4 base = texture2D(baseTexture, uv).rgba;
113107
#else
114108
vec4 col = vec4(color.rgb, base.a);
115109
col *= gl_Color;
116-
col = col * col; // SRGB -> Linear
117-
col *= 1.8;
118-
col.r = 1.0 - exp(1.0 - col.r) / e;
119-
col.g = 1.0 - exp(1.0 - col.g) / e;
120-
col.b = 1.0 - exp(1.0 - col.b) / e;
121-
col = sqrt(col); // Linear -> SRGB
122110
if(fogDistance != 0.0){
123111
float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
124112
col = mix(col, skyBgColor, d);

‎client/shaders/nodes_shader/opengl_vertex.glsl

+13-7
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,35 @@ void main(void)
6363

6464
vec3 normal, tangent, binormal;
6565
normal = normalize(gl_NormalMatrix * gl_Normal);
66+
float tileContrast = 1.0;
6667
if (gl_Normal.x > 0.5) {
6768
// 1.0, 0.0, 0.0
69+
tileContrast = 0.8;
6870
tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, -1.0));
6971
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
7072
} else if (gl_Normal.x < -0.5) {
7173
// -1.0, 0.0, 0.0
74+
tileContrast = 0.8;
7275
tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
7376
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
7477
} else if (gl_Normal.y > 0.5) {
7578
// 0.0, 1.0, 0.0
79+
tileContrast = 1.2;
7680
tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
7781
binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
7882
} else if (gl_Normal.y < -0.5) {
7983
// 0.0, -1.0, 0.0
84+
tileContrast = 0.3;
8085
tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
8186
binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
8287
} else if (gl_Normal.z > 0.5) {
8388
// 0.0, 0.0, 1.0
89+
tileContrast = 0.5;
8490
tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
8591
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
8692
} else if (gl_Normal.z < -0.5) {
8793
// 0.0, 0.0, -1.0
94+
tileContrast = 0.5;
8895
tangent = normalize(gl_NormalMatrix * vec3(-1.0, 0.0, 0.0));
8996
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
9097
}
@@ -108,7 +115,7 @@ void main(void)
108115

109116
// Moonlight is blue
110117
b += (day - night) / 13.0;
111-
rg -= (day - night) / 23.0;
118+
rg -= (day - night) / 13.0;
112119

113120
// Emphase blue a bit in darker places
114121
// See C++ implementation in mapblock_mesh.cpp finalColorBlend()
@@ -118,18 +125,17 @@ void main(void)
118125
// See C++ implementation in mapblock_mesh.cpp finalColorBlend()
119126
rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065);
120127

121-
color.r = clamp(rg,0.0,1.0);
122-
color.g = clamp(rg,0.0,1.0);
123-
color.b = clamp(b,0.0,1.0);
128+
color.r = rg;
129+
color.g = rg;
130+
color.b = b;
124131

125132
#if !(MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE)
126133
// Make sides and bottom darker than the top
127134
color = color * color; // SRGB -> Linear
128-
if(gl_Normal.y <= 0.5)
129-
color *= 0.6;
135+
color *= tileContrast;
130136
color = sqrt(color); // Linear -> SRGB
131137
#endif
132138

133139
color.a = gl_Color.a;
134-
gl_FrontColor = gl_BackColor = color;
140+
gl_FrontColor = gl_BackColor = clamp(color,0.0,1.0);
135141
}

‎client/shaders/water_surface_shader/opengl_fragment.glsl

-12
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,6 @@ vec4 base = texture2D(baseTexture, uv).rgba;
9999
float alpha = gl_Color.a;
100100
vec4 col = vec4(color.rgb, alpha);
101101
col *= gl_Color;
102-
col = col * col; // SRGB -> Linear
103-
col *= 1.8;
104-
col.r = 1.0 - exp(1.0 - col.r) / e;
105-
col.g = 1.0 - exp(1.0 - col.g) / e;
106-
col.b = 1.0 - exp(1.0 - col.b) / e;
107-
col = sqrt(col); // Linear -> SRGB
108102
if(fogDistance != 0.0){
109103
float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
110104
alpha = mix(alpha, 0.0, d);
@@ -113,12 +107,6 @@ vec4 base = texture2D(baseTexture, uv).rgba;
113107
#else
114108
vec4 col = vec4(color.rgb, base.a);
115109
col *= gl_Color;
116-
col = col * col; // SRGB -> Linear
117-
col *= 1.8;
118-
col.r = 1.0 - exp(1.0 - col.r) / e;
119-
col.g = 1.0 - exp(1.0 - col.g) / e;
120-
col.b = 1.0 - exp(1.0 - col.b) / e;
121-
col = sqrt(col); // Linear -> SRGB
122110
if(fogDistance != 0.0){
123111
float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
124112
col = mix(col, skyBgColor, d);

‎client/shaders/water_surface_shader/opengl_vertex.glsl

+13-7
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,35 @@ void main(void)
6363

6464
vec3 normal, tangent, binormal;
6565
normal = normalize(gl_NormalMatrix * gl_Normal);
66+
float tileContrast = 1.0;
6667
if (gl_Normal.x > 0.5) {
6768
// 1.0, 0.0, 0.0
69+
tileContrast = 0.8;
6870
tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, -1.0));
6971
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
7072
} else if (gl_Normal.x < -0.5) {
7173
// -1.0, 0.0, 0.0
74+
tileContrast = 0.8;
7275
tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
7376
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
7477
} else if (gl_Normal.y > 0.5) {
7578
// 0.0, 1.0, 0.0
79+
tileContrast = 1.2;
7680
tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
7781
binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
7882
} else if (gl_Normal.y < -0.5) {
7983
// 0.0, -1.0, 0.0
84+
tileContrast = 0.3;
8085
tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
8186
binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
8287
} else if (gl_Normal.z > 0.5) {
8388
// 0.0, 0.0, 1.0
89+
tileContrast = 0.5;
8490
tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
8591
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
8692
} else if (gl_Normal.z < -0.5) {
8793
// 0.0, 0.0, -1.0
94+
tileContrast = 0.5;
8895
tangent = normalize(gl_NormalMatrix * vec3(-1.0, 0.0, 0.0));
8996
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
9097
}
@@ -108,7 +115,7 @@ void main(void)
108115

109116
// Moonlight is blue
110117
b += (day - night) / 13.0;
111-
rg -= (day - night) / 23.0;
118+
rg -= (day - night) / 13.0;
112119

113120
// Emphase blue a bit in darker places
114121
// See C++ implementation in mapblock_mesh.cpp finalColorBlend()
@@ -118,18 +125,17 @@ void main(void)
118125
// See C++ implementation in mapblock_mesh.cpp finalColorBlend()
119126
rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065);
120127

121-
color.r = clamp(rg,0.0,1.0);
122-
color.g = clamp(rg,0.0,1.0);
123-
color.b = clamp(b,0.0,1.0);
128+
color.r = rg;
129+
color.g = rg;
130+
color.b = b;
124131

125132
#if !(MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE)
126133
// Make sides and bottom darker than the top
127134
color = color * color; // SRGB -> Linear
128-
if(gl_Normal.y <= 0.5)
129-
color *= 0.6;
135+
color *= tileContrast;
130136
color = sqrt(color); // Linear -> SRGB
131137
#endif
132138

133139
color.a = gl_Color.a;
134-
gl_FrontColor = gl_BackColor = color;
140+
gl_FrontColor = gl_BackColor = clamp(color,0.0,1.0);
135141
}

‎src/mapblock_mesh.cpp

+26-7
Original file line numberDiff line numberDiff line change
@@ -1397,13 +1397,32 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
13971397
u8 night = j->second.second;
13981398
finalColorBlend(vertices[vertexIndex].Color,
13991399
day, night, daynight_ratio);
1400-
// Brighten topside (no shaders)
1401-
if(vertices[vertexIndex].Normal.Y > 0.5)
1402-
{
1403-
video::SColor &vc = vertices[vertexIndex].Color;
1404-
vc.setRed (srgb_linear_multiply(vc.getRed(), 1.3, 255.0));
1405-
vc.setGreen(srgb_linear_multiply(vc.getGreen(), 1.3, 255.0));
1406-
vc.setBlue (srgb_linear_multiply(vc.getBlue(), 1.3, 255.0));
1400+
// Make sides and bottom darker than the top
1401+
video::SColor &vc = vertices[vertexIndex].Color;
1402+
if(vertices[vertexIndex].Normal.Y > 0.5) {
1403+
vc.setRed (srgb_linear_multiply(vc.getRed(), 1.2, 255.0));
1404+
vc.setGreen(srgb_linear_multiply(vc.getGreen(), 1.2, 255.0));
1405+
vc.setBlue (srgb_linear_multiply(vc.getBlue(), 1.2, 255.0));
1406+
} else if (vertices[vertexIndex].Normal.Y < -0.5) {
1407+
vc.setRed (srgb_linear_multiply(vc.getRed(), 0.3, 255.0));
1408+
vc.setGreen(srgb_linear_multiply(vc.getGreen(), 0.3, 255.0));
1409+
vc.setBlue (srgb_linear_multiply(vc.getBlue(), 0.3, 255.0));
1410+
} else if (vertices[vertexIndex].Normal.X > 0.5) {
1411+
vc.setRed (srgb_linear_multiply(vc.getRed(), 0.8, 255.0));
1412+
vc.setGreen(srgb_linear_multiply(vc.getGreen(), 0.8, 255.0));
1413+
vc.setBlue (srgb_linear_multiply(vc.getBlue(), 0.8, 255.0));
1414+
} else if (vertices[vertexIndex].Normal.X < -0.5) {
1415+
vc.setRed (srgb_linear_multiply(vc.getRed(), 0.8, 255.0));
1416+
vc.setGreen(srgb_linear_multiply(vc.getGreen(), 0.8, 255.0));
1417+
vc.setBlue (srgb_linear_multiply(vc.getBlue(), 0.8, 255.0));
1418+
} else if (vertices[vertexIndex].Normal.Z > 0.5) {
1419+
vc.setRed (srgb_linear_multiply(vc.getRed(), 0.5, 255.0));
1420+
vc.setGreen(srgb_linear_multiply(vc.getGreen(), 0.5, 255.0));
1421+
vc.setBlue (srgb_linear_multiply(vc.getBlue(), 0.5, 255.0));
1422+
} else if (vertices[vertexIndex].Normal.Z < -0.5) {
1423+
vc.setRed (srgb_linear_multiply(vc.getRed(), 0.5, 255.0));
1424+
vc.setGreen(srgb_linear_multiply(vc.getGreen(), 0.5, 255.0));
1425+
vc.setBlue (srgb_linear_multiply(vc.getBlue(), 0.5, 255.0));
14071426
}
14081427
}
14091428
}

0 commit comments

Comments
 (0)
Please sign in to comment.