Skip to content
Permalink
Browse files
Shadow mapping render pass (#11244)

Co-authored-by: x2048 <codeforsmile@gmail.com>
  • Loading branch information
0xLiso and x2048 committed Jun 6, 2021
1 parent 46f42e1 commit c47313db65f968559711ac1b505ef341a9872017
Showing with 2,624 additions and 38 deletions.
  1. +56 −2 builtin/mainmenu/tab_settings.lua
  2. +52 −0 builtin/settingtypes.txt
  3. +429 −2 client/shaders/nodes_shader/opengl_fragment.glsl
  4. +54 −5 client/shaders/nodes_shader/opengl_vertex.glsl
  5. +292 −5 client/shaders/object_shader/opengl_fragment.glsl
  6. +46 −0 client/shaders/object_shader/opengl_vertex.glsl
  7. +13 −0 client/shaders/shadow_shaders/pass1_fragment.glsl
  8. +38 −0 client/shaders/shadow_shaders/pass1_trans_fragment.glsl
  9. +26 −0 client/shaders/shadow_shaders/pass1_trans_vertex.glsl
  10. +26 −0 client/shaders/shadow_shaders/pass1_vertex.glsl
  11. +23 −0 client/shaders/shadow_shaders/pass2_fragment.glsl
  12. +9 −0 client/shaders/shadow_shaders/pass2_vertex.glsl
  13. +4 −0 src/client/CMakeLists.txt
  14. +213 −5 src/client/clientmap.cpp
  15. +10 −1 src/client/clientmap.h
  16. +10 −3 src/client/content_cao.cpp
  17. +36 −1 src/client/game.cpp
  18. +5 −1 src/client/mapblock_mesh.cpp
  19. +19 −2 src/client/render/core.cpp
  20. +5 −0 src/client/render/core.h
  21. +11 −0 src/client/renderingengine.h
  22. +64 −0 src/client/shader.cpp
  23. +145 −0 src/client/shadows/dynamicshadows.cpp
  24. +102 −0 src/client/shadows/dynamicshadows.h
  25. +539 −0 src/client/shadows/dynamicshadowsrender.cpp
  26. +146 −0 src/client/shadows/dynamicshadowsrender.h
  27. +67 −0 src/client/shadows/shadowsScreenQuad.cpp
  28. +45 −0 src/client/shadows/shadowsScreenQuad.h
  29. +44 −0 src/client/shadows/shadowsshadercallbacks.cpp
  30. +34 −0 src/client/shadows/shadowsshadercallbacks.h
  31. +27 −11 src/client/sky.cpp
  32. +7 −0 src/client/sky.h
  33. +12 −0 src/client/wieldmesh.cpp
  34. +3 −0 src/client/wieldmesh.h
  35. +12 −0 src/defaultsettings.cpp
@@ -43,6 +43,14 @@ local labels = {
fgettext("2x"),
fgettext("4x"),
fgettext("8x")
},
shadow_levels = {
fgettext("Disabled"),
fgettext("Very Low"),
fgettext("Low"),
fgettext("Medium"),
fgettext("High"),
fgettext("Ultra High")
}
}

@@ -66,6 +74,10 @@ local dd_options = {
antialiasing = {
table.concat(labels.antialiasing, ","),
{"0", "2", "4", "8"}
},
shadow_levels = {
table.concat(labels.shadow_levels, ","),
{ "0", "1", "2", "3", "4", "5" }
}
}

@@ -110,6 +122,15 @@ local getSettingIndex = {
end
end
return 1
end,
ShadowMapping = function()
local shadow_setting = core.settings:get("shadow_levels")
for i = 1, #dd_options.shadow_levels[2] do
if shadow_setting == dd_options.shadow_levels[2][i] then
return i
end
end
return 1
end
}

@@ -197,7 +218,10 @@ local function formspec(tabview, name, tabdata)
"checkbox[8.25,1.5;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";"
.. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" ..
"checkbox[8.25,2;cb_waving_plants;" .. fgettext("Waving Plants") .. ";"
.. dump(core.settings:get_bool("enable_waving_plants")) .. "]"
.. dump(core.settings:get_bool("enable_waving_plants")) .. "]"..
"label[8.25,3.0;" .. fgettext("Dynamic shadows: ") .. "]" ..
"dropdown[8.25,3.5;3.5;dd_shadows;" .. dd_options.shadow_levels[1] .. ";"
.. getSettingIndex.ShadowMapping() .. "]"
else
tab_string = tab_string ..
"label[8.38,0.7;" .. core.colorize("#888888",
@@ -207,7 +231,9 @@ local function formspec(tabview, name, tabdata)
"label[8.38,1.7;" .. core.colorize("#888888",
fgettext("Waving Leaves")) .. "]" ..
"label[8.38,2.2;" .. core.colorize("#888888",
fgettext("Waving Plants")) .. "]"
fgettext("Waving Plants")) .. "]"..
"label[8.38,2.7;" .. core.colorize("#888888",
fgettext("Dynamic shadows")) .. "]"
end

return tab_string
@@ -333,6 +359,34 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
ddhandled = true
end

for i = 1, #labels.shadow_levels do
if fields["dd_shadows"] == labels.shadow_levels[i] then
core.settings:set("shadow_levels", dd_options.shadow_levels[2][i])
ddhandled = true
end
end

if fields["dd_shadows"] == labels.shadow_levels[1] then
core.settings:set("enable_dynamic_shadows", "false")
else
core.settings:set("enable_dynamic_shadows", "true")
local shadow_presets = {
[2] = { 80, 512, "true", 0, "false" },
[3] = { 120, 1024, "true", 1, "false" },
[4] = { 350, 2048, "true", 1, "false" },
[5] = { 350, 2048, "true", 2, "true" },
[6] = { 450, 4096, "true", 2, "true" },
}
local s = shadow_presets[table.indexof(labels.shadow_levels, fields["dd_shadows"])]
if s then
core.settings:set("shadow_map_max_distance", s[1])
core.settings:set("shadow_map_texture_size", s[2])
core.settings:set("shadow_map_texture_32bit", s[3])
core.settings:set("shadow_filters", s[4])
core.settings:set("shadow_map_color", s[5])
end
end

return ddhandled
end

@@ -582,6 +582,58 @@ enable_waving_leaves (Waving leaves) bool false
# Requires shaders to be enabled.
enable_waving_plants (Waving plants) bool false

[***Dynamic shadows]

# Set to true to enable Shadow Mapping.
# Requires shaders to be enabled.
enable_dynamic_shadows (Dynamic shadows) bool false

# Set the shadow strength.
# Lower value means lighter shadows, higher value means darker shadows.
shadow_strength (Shadow strength) float 0.2 0.05 1.0

# Maximum distance to render shadows.
shadow_map_max_distance (Shadow map max distance in nodes to render shadows) float 120.0 10.0 1000.0

# Texture size to render the shadow map on.
# This must be a power of two.
# Bigger numbers create better shadowsbut it is also more expensive.
shadow_map_texture_size (Shadow map texture size) int 1024 128 8192

# Sets shadow texture quality to 32 bits.
# On false, 16 bits texture will be used.
# This can cause much more artifacts in the shadow.
shadow_map_texture_32bit (Shadow map texture in 32 bits) bool true

# Enable poisson disk filtering.
# On true uses poisson disk to make "soft shadows". Otherwise uses PCF filtering.
shadow_poisson_filter (Poisson filtering) bool true

# Define shadow filtering quality
# This simulates the soft shadows effect by applying a PCF or poisson disk
# but also uses more resources.
shadow_filters (Shadow filter quality) enum 1 0,1,2

# Enable colored shadows.
# On true translucent nodes cast colored shadows. This is expensive.
shadow_map_color (Colored shadows) bool false


# Set the shadow update time.
# Lower value means shadows and map updates faster, but it consume more resources.
# Minimun value 0.001 seconds max value 0.2 seconds
shadow_update_time (Map update time) float 0.2 0.001 0.2

# Set the soft shadow radius size.
# Lower values mean sharper shadows bigger values softer.
# Minimun value 1.0 and max value 10.0
shadow_soft_radius (Soft shadow radius) float 1.0 1.0 10.0

# Set the tilt of Sun/Moon orbit in degrees
# Value of 0 means no tilt / vertical orbit.
# Minimun value 0.0 and max value 60.0
shadow_sky_body_orbit_tilt (Sky Body Orbit Tilt) float 0.0 0.0 60.0

[**Advanced]

# Arm inertia, gives a more realistic movement of

0 comments on commit c47313d

Please sign in to comment.