Skip to content
Permalink
Browse files

Shaders rework.

  • Loading branch information...
RealBadAngel authored and PilzAdam committed Dec 3, 2013
1 parent 60113bd commit 2330267d2207208799ad347ea0d129c0b4551d61
Showing with 914 additions and 539 deletions.
  1. +55 −19 builtin/mainmenu.lua
  2. 0 client/shaders/{bumpmaps_liquids → alpha_shader}/base.txt
  3. +67 −0 client/shaders/alpha_shader/opengl_fragment.glsl
  4. +99 −0 client/shaders/alpha_shader/opengl_vertex.glsl
  5. +0 −46 client/shaders/bumpmaps_liquids/opengl_fragment.glsl
  6. +0 −98 client/shaders/bumpmaps_liquids/opengl_vertex.glsl
  7. +0 −45 client/shaders/bumpmaps_solids/opengl_fragment.glsl
  8. +0 −98 client/shaders/bumpmaps_solids/opengl_vertex.glsl
  9. 0 client/shaders/{bumpmaps_solids → leaves_shader}/base.txt
  10. +54 −0 client/shaders/leaves_shader/opengl_fragment.glsl
  11. +87 −0 client/shaders/leaves_shader/opengl_vertex.glsl
  12. 0 client/shaders/{test_shader_2 → liquids_shader}/base.txt
  13. +53 −0 client/shaders/liquids_shader/opengl_fragment.glsl
  14. +25 −14 client/shaders/{test_shader_1 → liquids_shader}/opengl_vertex.glsl
  15. 0 client/shaders/{test_shader_1 → plants_shader}/base.txt
  16. +53 −0 client/shaders/plants_shader/opengl_fragment.glsl
  17. +87 −0 client/shaders/plants_shader/opengl_vertex.glsl
  18. +1 −0 client/shaders/solids_shader/base.txt
  19. +87 −0 client/shaders/solids_shader/opengl_fragment.glsl
  20. +99 −0 client/shaders/solids_shader/opengl_vertex.glsl
  21. +0 −25 client/shaders/test_shader_1/opengl_fragment.glsl
  22. +0 −23 client/shaders/test_shader_2/opengl_fragment.glsl
  23. +0 −51 client/shaders/test_shader_2/opengl_vertex.glsl
  24. +0 −1 client/shaders/test_shader_3/base.txt
  25. +0 −25 client/shaders/test_shader_3/opengl_fragment.glsl
  26. +0 −51 client/shaders/test_shader_3/opengl_vertex.glsl
  27. +16 −0 minetest.conf.example
  28. +9 −0 src/defaultsettings.cpp
  29. +54 −3 src/game.cpp
  30. +8 −3 src/itemdef.cpp
  31. +28 −33 src/mapblock_mesh.cpp
  32. +10 −3 src/nodedef.cpp
  33. +2 −0 src/nodedef.h
  34. +3 −0 src/script/common/c_content.cpp
  35. +17 −1 src/tile.h
  36. BIN textures/base/pack/disable_img.png
  37. BIN textures/base/pack/enable_img.png
@@ -687,7 +687,21 @@ function tabbuilder.handle_settings_buttons(fields)
if fields["cb_finite_liquid"] then
engine.setting_set("liquid_finite", fields["cb_finite_liquid"])
end

if fields["cb_bumpmapping"] then
engine.setting_set("enable_bumpmapping", fields["cb_bumpmapping"])
end
if fields["cb_parallax"] then
engine.setting_set("enable_parallax_occlusion", fields["cb_parallax"])
end
if fields["cb_waving_water"] then
engine.setting_set("enable_waving_water", fields["cb_waving_water"])
end
if fields["cb_waving_leaves"] then
engine.setting_set("enable_waving_leaves", fields["cb_waving_leaves"])
end
if fields["cb_waving_plants"] then
engine.setting_set("enable_waving_plants", fields["cb_waving_plants"])
end
if fields["btn_change_keys"] ~= nil then
engine.show_keys_menu()
end
@@ -923,35 +937,57 @@ end

--------------------------------------------------------------------------------
function tabbuilder.tab_settings()
return "vertlabel[0,0;" .. fgettext("SETTINGS") .. "]" ..
"checkbox[1,0.75;cb_fancy_trees;".. fgettext("Fancy trees") .. ";"
tab_string =
"vertlabel[0,0;" .. fgettext("SETTINGS") .. "]" ..
"checkbox[1,0;cb_fancy_trees;".. fgettext("Fancy Trees") .. ";"
.. dump(engine.setting_getbool("new_style_leaves")) .. "]"..
"checkbox[1,1.25;cb_smooth_lighting;".. fgettext("Smooth Lighting")
"checkbox[1,0.5;cb_smooth_lighting;".. fgettext("Smooth Lighting")
.. ";".. dump(engine.setting_getbool("smooth_lighting")) .. "]"..
"checkbox[1,1.75;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
"checkbox[1,1;cb_3d_clouds;".. fgettext("3D Clouds") .. ";"
.. dump(engine.setting_getbool("enable_3d_clouds")) .. "]"..
"checkbox[1,2.25;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
"checkbox[1,1.5;cb_opaque_water;".. fgettext("Opaque Water") .. ";"
.. dump(engine.setting_getbool("opaque_water")) .. "]"..
"checkbox[1,2.0;cb_pre_ivis;".. fgettext("Preload item visuals") .. ";"
.. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
"checkbox[1,2.5;cb_particles;".. fgettext("Enable Particles") .. ";"
.. dump(engine.setting_getbool("enable_particles")) .. "]"..
"checkbox[1,3.0;cb_finite_liquid;".. fgettext("Finite Liquid") .. ";"
.. dump(engine.setting_getbool("liquid_finite")) .. "]"..

"checkbox[4,0.75;cb_mipmapping;".. fgettext("Mip-Mapping") .. ";"
"checkbox[4.5,0;cb_mipmapping;".. fgettext("Mip-Mapping") .. ";"
.. dump(engine.setting_getbool("mip_map")) .. "]"..
"checkbox[4,1.25;cb_anisotrophic;".. fgettext("Anisotropic Filtering") .. ";"
"checkbox[4.5,0.5;cb_anisotrophic;".. fgettext("Anisotropic Filtering") .. ";"
.. dump(engine.setting_getbool("anisotropic_filter")) .. "]"..
"checkbox[4,1.75;cb_bilinear;".. fgettext("Bi-Linear Filtering") .. ";"
"checkbox[4.5,1.0;cb_bilinear;".. fgettext("Bi-Linear Filtering") .. ";"
.. dump(engine.setting_getbool("bilinear_filter")) .. "]"..
"checkbox[4,2.25;cb_trilinear;".. fgettext("Tri-Linear Filtering") .. ";"
"checkbox[4.5,1.5;cb_trilinear;".. fgettext("Tri-Linear Filtering") .. ";"
.. dump(engine.setting_getbool("trilinear_filter")) .. "]"..

"checkbox[7.5,0.75;cb_shaders;".. fgettext("Shaders") .. ";"
"checkbox[8,0;cb_shaders;".. fgettext("Shaders") .. ";"
.. dump(engine.setting_getbool("enable_shaders")) .. "]"..
"checkbox[7.5,1.25;cb_pre_ivis;".. fgettext("Preload item visuals") .. ";"
.. dump(engine.setting_getbool("preload_item_visuals")) .. "]"..
"checkbox[7.5,1.75;cb_particles;".. fgettext("Enable Particles") .. ";"
.. dump(engine.setting_getbool("enable_particles")) .. "]"..
"checkbox[7.5,2.25;cb_finite_liquid;".. fgettext("Finite Liquid") .. ";"
.. dump(engine.setting_getbool("liquid_finite")) .. "]"..

"button[1,4.25;2.25,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"
"button[1,4.5;2.25,0.5;btn_change_keys;".. fgettext("Change keys") .. "]"

if engine.setting_getbool("enable_shaders") then
tab_string = tab_string ..
"checkbox[8,0.5;cb_bumpmapping;".. fgettext("Bumpmapping") .. ";"
.. dump(engine.setting_getbool("enable_bumpmapping")) .. "]"..
"checkbox[8,1.0;cb_parallax;".. fgettext("Parallax Occlusion") .. ";"
.. dump(engine.setting_getbool("enable_parallax_occlusion")) .. "]"..
"checkbox[8,1.5;cb_waving_water;".. fgettext("Waving Water") .. ";"
.. dump(engine.setting_getbool("enable_waving_water")) .. "]"..
"checkbox[8,2.0;cb_waving_leaves;".. fgettext("Waving Leaves") .. ";"
.. dump(engine.setting_getbool("enable_waving_leaves")) .. "]"..
"checkbox[8,2.5;cb_waving_plants;".. fgettext("Waving Plants") .. ";"
.. dump(engine.setting_getbool("enable_waving_plants")) .. "]"
else
tab_string = tab_string ..
"textlist[8.33,0.7;4,1;;#888888" .. fgettext("Bumpmapping") .. ";0;true]" ..
"textlist[8.33,1.2;4,1;;#888888" .. fgettext("Parallax Occlusion") .. ";0;true]" ..
"textlist[8.33,1.7;4,1;;#888888" .. fgettext("Waving Water") .. ";0;true]" ..
"textlist[8.33,2.2;4,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" ..
"textlist[8.33,2.7;4,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]"
end
return tab_string
end

--------------------------------------------------------------------------------
@@ -0,0 +1,67 @@
#version 120

uniform sampler2D baseTexture;
uniform sampler2D normalTexture;
uniform sampler2D useNormalmap;

uniform float enableBumpmapping;
uniform float enableParallaxOcclusion;
uniform float parallaxOcclusionScale;
uniform float parallaxOcclusionBias;


uniform vec4 skyBgColor;
uniform float fogDistance;

varying vec3 vPosition;
varying vec3 tsEyeVec;
varying vec3 eyeVec;

const float e = 2.718281828459;

void main (void)
{
float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r;
float enable_bumpmapping = enableBumpmapping;

vec3 color;
vec2 uv = gl_TexCoord[0].st;
float height;
vec2 tsEye = vec2(tsEyeVec.x,-tsEyeVec.y);

if ((enableParallaxOcclusion == 1.0) && (use_normalmap > 0.0)) {
float map_height = texture2D(normalTexture, uv).a;
if (map_height < 1.0){
float height = parallaxOcclusionScale * map_height - parallaxOcclusionBias;
uv = uv + height * tsEye;
}
}

if ((enable_bumpmapping == 1.0) && (use_normalmap > 0.0)) {
vec3 base = texture2D(baseTexture, uv).rgb;
vec3 vVec = normalize(eyeVec);
vec3 bump = normalize(texture2D(normalTexture, uv).xyz * 2.0 - 1.0);
vec3 R = reflect(-vVec, bump);
vec3 lVec = normalize(vVec);
float diffuse = max(dot(lVec, bump), 0.0);
float specular = pow(clamp(dot(R, lVec), 0.0, 1.0),1.0);
color = mix (base,diffuse*base,1.0) + 0.1 * specular * diffuse;
} else {
color = texture2D(baseTexture, uv).rgb;
}

float alpha = texture2D(baseTexture, uv).a;
vec4 col = vec4(color.r, color.g, color.b, 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));
col = mix(col, skyBgColor, d);
}
gl_FragColor = vec4(col.r, col.g, col.b, alpha);
}
@@ -0,0 +1,99 @@
#version 120

uniform mat4 mWorldViewProj;
uniform mat4 mInvWorld;
uniform mat4 mTransWorld;
uniform float dayNightRatio;

uniform vec3 eyePosition;

varying vec3 vPosition;
varying vec3 eyeVec;
varying vec3 tsEyeVec;

void main(void)
{
gl_Position = mWorldViewProj * gl_Vertex;
vPosition = (mWorldViewProj * gl_Vertex).xyz;

vec3 normal,tangent,binormal;
normal = normalize(gl_NormalMatrix * gl_Normal);

if (gl_Normal.x > 0.5) {
// 1.0, 0.0, 0.0
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
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
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
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
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
tangent = normalize(gl_NormalMatrix * vec3(-1.0, 0.0, 0.0));
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
}

mat3 tbnMatrix = mat3(tangent.x, binormal.x, normal.x,
tangent.y, binormal.y, normal.y,
tangent.z, binormal.z, normal.z);

eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;
tsEyeVec = normalize(eyeVec * tbnMatrix);

vec4 color;
//color = vec4(1.0, 1.0, 1.0, 1.0);

float day = gl_Color.r;
float night = gl_Color.g;
float light_source = gl_Color.b;

/*color.r = mix(night, day, dayNightRatio);
color.g = color.r;
color.b = color.r;*/

float rg = mix(night, day, dayNightRatio);
rg += light_source * 2.5; // Make light sources brighter
float b = rg;

// Moonlight is blue
b += (day - night) / 13.0;
rg -= (day - night) / 13.0;

// Emphase blue a bit in darker places
// See C++ implementation in mapblock_mesh.cpp finalColorBlend()
b += max(0.0, (1.0 - abs(b - 0.13)/0.17) * 0.025);

// Artificial light is yellow-ish
// 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);

// Make sides and bottom darker than the top
color = color * color; // SRGB -> Linear
if(gl_Normal.y <= 0.5)
color *= 0.6;
//color *= 0.7;
color = sqrt(color); // Linear -> SRGB

color.a = gl_Color.a;

gl_FrontColor = gl_BackColor = color;

gl_TexCoord[0] = gl_MultiTexCoord0;

}

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 2330267

Please sign in to comment.
You can’t perform that action at this time.