Skip to content

Commit 2330267

Browse files
RealBadAngelPilzAdam
authored andcommittedDec 3, 2013
Shaders rework.
1 parent 60113bd commit 2330267

37 files changed

+914
-539
lines changed
 

‎builtin/mainmenu.lua

+55-19
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,21 @@ function tabbuilder.handle_settings_buttons(fields)
687687
if fields["cb_finite_liquid"] then
688688
engine.setting_set("liquid_finite", fields["cb_finite_liquid"])
689689
end
690-
690+
if fields["cb_bumpmapping"] then
691+
engine.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
692+
end
693+
if fields["cb_parallax"] then
694+
engine.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
695+
end
696+
if fields["cb_waving_water"] then
697+
engine.setting_set("enable_waving_water", fields["cb_waving_water"])
698+
end
699+
if fields["cb_waving_leaves"] then
700+
engine.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
701+
end
702+
if fields["cb_waving_plants"] then
703+
engine.setting_set("enable_waving_plants", fields["cb_waving_plants"])
704+
end
691705
if fields["btn_change_keys"] ~= nil then
692706
engine.show_keys_menu()
693707
end
@@ -923,35 +937,57 @@ end
923937

924938
--------------------------------------------------------------------------------
925939
function tabbuilder.tab_settings()
926-
return "vertlabel[0,0;" .. fgettext("SETTINGS") .. "]" ..
927-
"checkbox[1,0.75;cb_fancy_trees;".. fgettext("Fancy trees") .. ";"
940+
tab_string =
941+
"vertlabel[0,0;" .. fgettext("SETTINGS") .. "]" ..
942+
"checkbox[1,0;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";"
928943
.. dump(engine.setting_getbool("new_style_leaves")) .. "]"..
929-
"checkbox[1,1.25;cb_smooth_lighting;".. fgettext("Smooth Lighting")
944+
"checkbox[1,0.5;cb_smooth_lighting;".. fgettext("Smooth Lighting")
930945
.. ";".. dump(engine.setting_getbool("smooth_lighting")) .. "]"..
931-
"checkbox[1,1.75;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
946+
"checkbox[1,1;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
932947
.. dump(engine.setting_getbool("enable_3d_clouds")) .. "]"..
933-
"checkbox[1,2.25;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
948+
"checkbox[1,1.5;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
934949
.. dump(engine.setting_getbool("opaque_water")) .. "]"..
950+
"checkbox[1,2.0;cb_pre_ivis;".. fgettext("Preload item visuals") .. ";"
951+
.. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
952+
"checkbox[1,2.5;cb_particles;".. fgettext("Enable Particles") .. ";"
953+
.. dump(engine.setting_getbool("enable_particles")) .. "]"..
954+
"checkbox[1,3.0;cb_finite_liquid;".. fgettext("Finite Liquid") .. ";"
955+
.. dump(engine.setting_getbool("liquid_finite")) .. "]"..
935956

936-
"checkbox[4,0.75;cb_mipmapping;".. fgettext("Mip-Mapping") .. ";"
957+
"checkbox[4.5,0;cb_mipmapping;".. fgettext("Mip-Mapping") .. ";"
937958
.. dump(engine.setting_getbool("mip_map")) .. "]"..
938-
"checkbox[4,1.25;cb_anisotrophic;".. fgettext("Anisotropic Filtering") .. ";"
959+
"checkbox[4.5,0.5;cb_anisotrophic;".. fgettext("Anisotropic Filtering") .. ";"
939960
.. dump(engine.setting_getbool("anisotropic_filter")) .. "]"..
940-
"checkbox[4,1.75;cb_bilinear;".. fgettext("Bi-Linear Filtering") .. ";"
961+
"checkbox[4.5,1.0;cb_bilinear;".. fgettext("Bi-Linear Filtering") .. ";"
941962
.. dump(engine.setting_getbool("bilinear_filter")) .. "]"..
942-
"checkbox[4,2.25;cb_trilinear;".. fgettext("Tri-Linear Filtering") .. ";"
963+
"checkbox[4.5,1.5;cb_trilinear;".. fgettext("Tri-Linear Filtering") .. ";"
943964
.. dump(engine.setting_getbool("trilinear_filter")) .. "]"..
944965

945-
"checkbox[7.5,0.75;cb_shaders;".. fgettext("Shaders") .. ";"
966+
"checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";"
946967
.. dump(engine.setting_getbool("enable_shaders")) .. "]"..
947-
"checkbox[7.5,1.25;cb_pre_ivis;".. fgettext("Preload item visuals") .. ";"
948-
.. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
949-
"checkbox[7.5,1.75;cb_particles;".. fgettext("Enable Particles") .. ";"
950-
.. dump(engine.setting_getbool("enable_particles")) .. "]"..
951-
"checkbox[7.5,2.25;cb_finite_liquid;".. fgettext("Finite Liquid") .. ";"
952-
.. dump(engine.setting_getbool("liquid_finite")) .. "]"..
953-
954-
"button[1,4.25;2.25,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
968+
"button[1,4.5;2.25,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
969+
970+
if engine.setting_getbool("enable_shaders") then
971+
tab_string = tab_string ..
972+
"checkbox[8,0.5;cb_bumpmapping;".. fgettext("Bumpmapping") .. ";"
973+
.. dump(engine.setting_getbool("enable_bumpmapping")) .. "]"..
974+
"checkbox[8,1.0;cb_parallax;".. fgettext("Parallax Occlusion") .. ";"
975+
.. dump(engine.setting_getbool("enable_parallax_occlusion")) .. "]"..
976+
"checkbox[8,1.5;cb_waving_water;".. fgettext("Waving Water") .. ";"
977+
.. dump(engine.setting_getbool("enable_waving_water")) .. "]"..
978+
"checkbox[8,2.0;cb_waving_leaves;".. fgettext("Waving Leaves") .. ";"
979+
.. dump(engine.setting_getbool("enable_waving_leaves")) .. "]"..
980+
"checkbox[8,2.5;cb_waving_plants;".. fgettext("Waving Plants") .. ";"
981+
.. dump(engine.setting_getbool("enable_waving_plants")) .. "]"
982+
else
983+
tab_string = tab_string ..
984+
"textlist[8.33,0.7;4,1;;#888888" .. fgettext("Bumpmapping") .. ";0;true]" ..
985+
"textlist[8.33,1.2;4,1;;#888888" .. fgettext("Parallax Occlusion") .. ";0;true]" ..
986+
"textlist[8.33,1.7;4,1;;#888888" .. fgettext("Waving Water") .. ";0;true]" ..
987+
"textlist[8.33,2.2;4,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" ..
988+
"textlist[8.33,2.7;4,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]"
989+
end
990+
return tab_string
955991
end
956992

957993
--------------------------------------------------------------------------------
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#version 120
2+
3+
uniform sampler2D baseTexture;
4+
uniform sampler2D normalTexture;
5+
uniform sampler2D useNormalmap;
6+
7+
uniform float enableBumpmapping;
8+
uniform float enableParallaxOcclusion;
9+
uniform float parallaxOcclusionScale;
10+
uniform float parallaxOcclusionBias;
11+
12+
13+
uniform vec4 skyBgColor;
14+
uniform float fogDistance;
15+
16+
varying vec3 vPosition;
17+
varying vec3 tsEyeVec;
18+
varying vec3 eyeVec;
19+
20+
const float e = 2.718281828459;
21+
22+
void main (void)
23+
{
24+
float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r;
25+
float enable_bumpmapping = enableBumpmapping;
26+
27+
vec3 color;
28+
vec2 uv = gl_TexCoord[0].st;
29+
float height;
30+
vec2 tsEye = vec2(tsEyeVec.x,-tsEyeVec.y);
31+
32+
if ((enableParallaxOcclusion == 1.0) && (use_normalmap > 0.0)) {
33+
float map_height = texture2D(normalTexture, uv).a;
34+
if (map_height < 1.0){
35+
float height = parallaxOcclusionScale * map_height - parallaxOcclusionBias;
36+
uv = uv + height * tsEye;
37+
}
38+
}
39+
40+
if ((enable_bumpmapping == 1.0) && (use_normalmap > 0.0)) {
41+
vec3 base = texture2D(baseTexture, uv).rgb;
42+
vec3 vVec = normalize(eyeVec);
43+
vec3 bump = normalize(texture2D(normalTexture, uv).xyz * 2.0 - 1.0);
44+
vec3 R = reflect(-vVec, bump);
45+
vec3 lVec = normalize(vVec);
46+
float diffuse = max(dot(lVec, bump), 0.0);
47+
float specular = pow(clamp(dot(R, lVec), 0.0, 1.0),1.0);
48+
color = mix (base,diffuse*base,1.0) + 0.1 * specular * diffuse;
49+
} else {
50+
color = texture2D(baseTexture, uv).rgb;
51+
}
52+
53+
float alpha = texture2D(baseTexture, uv).a;
54+
vec4 col = vec4(color.r, color.g, color.b, alpha);
55+
col *= gl_Color;
56+
col = col * col; // SRGB -> Linear
57+
col *= 1.8;
58+
col.r = 1.0 - exp(1.0 - col.r) / e;
59+
col.g = 1.0 - exp(1.0 - col.g) / e;
60+
col.b = 1.0 - exp(1.0 - col.b) / e;
61+
col = sqrt(col); // Linear -> SRGB
62+
if(fogDistance != 0.0){
63+
float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
64+
col = mix(col, skyBgColor, d);
65+
}
66+
gl_FragColor = vec4(col.r, col.g, col.b, alpha);
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#version 120
2+
3+
uniform mat4 mWorldViewProj;
4+
uniform mat4 mInvWorld;
5+
uniform mat4 mTransWorld;
6+
uniform float dayNightRatio;
7+
8+
uniform vec3 eyePosition;
9+
10+
varying vec3 vPosition;
11+
varying vec3 eyeVec;
12+
varying vec3 tsEyeVec;
13+
14+
void main(void)
15+
{
16+
gl_Position = mWorldViewProj * gl_Vertex;
17+
vPosition = (mWorldViewProj * gl_Vertex).xyz;
18+
19+
vec3 normal,tangent,binormal;
20+
normal = normalize(gl_NormalMatrix * gl_Normal);
21+
22+
if (gl_Normal.x > 0.5) {
23+
// 1.0, 0.0, 0.0
24+
tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, -1.0));
25+
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
26+
} else if (gl_Normal.x < -0.5) {
27+
// -1.0, 0.0, 0.0
28+
tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
29+
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
30+
} else if (gl_Normal.y > 0.5) {
31+
// 0.0, 1.0, 0.0
32+
tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
33+
binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
34+
} else if (gl_Normal.y < -0.5) {
35+
// 0.0, -1.0, 0.0
36+
tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
37+
binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
38+
} else if (gl_Normal.z > 0.5) {
39+
// 0.0, 0.0, 1.0
40+
tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
41+
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
42+
} else if (gl_Normal.z < -0.5) {
43+
// 0.0, 0.0, -1.0
44+
tangent = normalize(gl_NormalMatrix * vec3(-1.0, 0.0, 0.0));
45+
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
46+
}
47+
48+
mat3 tbnMatrix = mat3(tangent.x, binormal.x, normal.x,
49+
tangent.y, binormal.y, normal.y,
50+
tangent.z, binormal.z, normal.z);
51+
52+
eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;
53+
tsEyeVec = normalize(eyeVec * tbnMatrix);
54+
55+
vec4 color;
56+
//color = vec4(1.0, 1.0, 1.0, 1.0);
57+
58+
float day = gl_Color.r;
59+
float night = gl_Color.g;
60+
float light_source = gl_Color.b;
61+
62+
/*color.r = mix(night, day, dayNightRatio);
63+
color.g = color.r;
64+
color.b = color.r;*/
65+
66+
float rg = mix(night, day, dayNightRatio);
67+
rg += light_source * 2.5; // Make light sources brighter
68+
float b = rg;
69+
70+
// Moonlight is blue
71+
b += (day - night) / 13.0;
72+
rg -= (day - night) / 13.0;
73+
74+
// Emphase blue a bit in darker places
75+
// See C++ implementation in mapblock_mesh.cpp finalColorBlend()
76+
b += max(0.0, (1.0 - abs(b - 0.13)/0.17) * 0.025);
77+
78+
// Artificial light is yellow-ish
79+
// See C++ implementation in mapblock_mesh.cpp finalColorBlend()
80+
rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065);
81+
82+
color.r = clamp(rg,0.0,1.0);
83+
color.g = clamp(rg,0.0,1.0);
84+
color.b = clamp(b,0.0,1.0);
85+
86+
// Make sides and bottom darker than the top
87+
color = color * color; // SRGB -> Linear
88+
if(gl_Normal.y <= 0.5)
89+
color *= 0.6;
90+
//color *= 0.7;
91+
color = sqrt(color); // Linear -> SRGB
92+
93+
color.a = gl_Color.a;
94+
95+
gl_FrontColor = gl_BackColor = color;
96+
97+
gl_TexCoord[0] = gl_MultiTexCoord0;
98+
99+
}

‎client/shaders/bumpmaps_liquids/opengl_fragment.glsl

-46
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.