diff --git a/common/configs/LavaMaps/AcidicQuarry.lua b/common/configs/LavaMaps/AcidicQuarry.lua new file mode 100644 index 00000000000..c321930dc43 --- /dev/null +++ b/common/configs/LavaMaps/AcidicQuarry.lua @@ -0,0 +1,26 @@ +local conf = { + grow = 0, + effectBurst = false, + level = 5, + colorCorrection = "vec3(0.26, 1.0, 0.03)", + --coastColor = "vec3(0.6, 0.7, 0.03)", + coastLightBoost = 1.2, + coastWidth = 10.0, + fogColor = "vec3(1.60, 0.8, 0.3)", + --coastWidth = 30.0, + lavaParallaxDepth = 32.0, + lavaParallaxOffset = 0.2, + swirlFreq = 0.008, + swirlAmp = 0.017, + uvScale = 2.2, + specularExp = 12.0, + tideAmplitude = 3, + tidePeriod = 40, + fogFactor = 0.13, + fogHeight = 36, + fogAbove = 0.1, + fogDistortion = 2.0, + tideRhym = { { 4, 0.05, 5*6000 } }, +} + +return conf diff --git a/common/configs/LavaMaps/Claymore.lua b/common/configs/LavaMaps/Claymore.lua new file mode 100644 index 00000000000..5eaa03e0da1 --- /dev/null +++ b/common/configs/LavaMaps/Claymore.lua @@ -0,0 +1,18 @@ +local conf = { + grow = 0, + effectBurst = false, + diffuseEmitTex = "LuaUI/images/lava/lava2_diffuseemitblue.dds", + colorCorrection = "vec3(0.4, 0.5, 0.4)", + coastColor = "vec3(0.24, 0.46, 0.5)", + coastLightBoost = 0.3, + fogColor = "vec3(0.24, 0.46, 0.5)", + fogFactor = 0.01, + fogHeight = 15, + fogAbove = 4.0, + fogDistortion = 2.0, + tideAmplitude = 0.3, + tidePeriod = 1000, + tideRhym = { { -1, 0.05, 5*6000 } }, +} + +return conf diff --git a/common/configs/LavaMaps/Forge.lua b/common/configs/LavaMaps/Forge.lua new file mode 100644 index 00000000000..aeb5268b621 --- /dev/null +++ b/common/configs/LavaMaps/Forge.lua @@ -0,0 +1,22 @@ +local conf = { + level = 0, + damage = 150, + tideAmplitude = 3, + tidePeriod = 95, + diffuseEmitTex = "LuaUI/images/lava/lava7_diffuseemit.dds", + normalHeightTex = "LuaUI/images/lava/lava7_normalheight.dds", + losDarkness = 0.7, + colorCorrection = "vec3(1.1, 1.0, 0.88)", + shadowStrength = 1.0, + coastColor = "vec3(2.2, 0.4, 0.0)", + coastLightBoost = 0.7, + coastWidth = 36.0, + fogFactor = 0.02, + fogColor = "vec3(2.0, 0.31, 0.0)", + fogHeight = 35, + fogAbove = 0.18, + + tideRhym = { { -1, 0.25, 5*6000 } }, +} + +return conf diff --git a/common/configs/LavaMaps/Ghenna Rising.lua b/common/configs/LavaMaps/Ghenna Rising.lua new file mode 100644 index 00000000000..ad185b4c46d --- /dev/null +++ b/common/configs/LavaMaps/Ghenna Rising.lua @@ -0,0 +1,21 @@ +local conf = { + level = 251, + damage = 750, + colorCorrection = "vec3(0.7, 0.7, 0.7)", + swirlFreq = 0.017, + swirlAmp = 0.0024, + tideAmplitude = 3, + specularExp = 4.0, + shadowStrength = 0.9, + coastLightBoost = 0.8, + uvScale = 1.5, + tideRhym = { { 250, 0.10, 15 }, + { 415, 0.05, 30 }, + { 250, 0.10, 5*60 }, + { 415, 0.05, 30 }, + { 250, 0.10, 5*60 }, + { 415, 0.05, 3*30 }, + { 250, 0.10, 10*60 } }, +} + +return conf diff --git a/common/configs/LavaMaps/Hotstepper 5.lua b/common/configs/LavaMaps/Hotstepper 5.lua new file mode 100644 index 00000000000..4f85211cf34 --- /dev/null +++ b/common/configs/LavaMaps/Hotstepper 5.lua @@ -0,0 +1,16 @@ +local conf = { + level = 100, + damage = 130, + tideRhym = { { 90, 0.25, 5*60 }, + { 215, 0.10, 5 }, + { 90, 0.25, 5*60 }, + { 290, 0.15, 5 }, + { 90, 0.25, 4*60 }, + { 355, 0.20, 5 }, + { 90, 0.25, 4*60 }, + { 390, 0.20, 5 }, + { 90, 0.25, 2*60 }, + { 440, 0.04, 2*60 } }, +} + +return conf diff --git a/common/configs/LavaMaps/Hyperion Shale.lua b/common/configs/LavaMaps/Hyperion Shale.lua new file mode 100644 index 00000000000..a081c4ff864 --- /dev/null +++ b/common/configs/LavaMaps/Hyperion Shale.lua @@ -0,0 +1,18 @@ +local conf = { + grow = 0, + effectBurst = false, + diffuseEmitTex = "LuaUI/images/lava/lava2_diffuseemitblue.dds", + colorCorrection = "vec3(1.0, 1.0, 1.0)", + coastColor = "vec3(0.0, 0.35, 0.9)", + coastLightBoost = 0.3, + fogColor = "vec3(0.0, 0.3, 1.0)", + fogFactor = 0.01, + fogHeight = 15, + fogAbove = 4.0, + fogDistortion = 2.0, + tideAmplitude = 0.3, + tidePeriod = 1000, + tideRhym = { { -1, 0.05, 5*6000 } }, +} + +return conf diff --git a/common/configs/LavaMaps/Incandescence Remake.lua b/common/configs/LavaMaps/Incandescence Remake.lua new file mode 100644 index 00000000000..ad65622d5ee --- /dev/null +++ b/common/configs/LavaMaps/Incandescence Remake.lua @@ -0,0 +1,22 @@ +local conf = { + level = 207, + damage = 150, + tideAmplitude = 3, + tidePeriod = 95, + diffuseEmitTex = "LuaUI/images/lava/lava7_diffuseemit.dds", + normalHeightTex = "LuaUI/images/lava/lava7_normalheight.dds", + losDarkness = 0.7, + colorCorrection = "vec3(1.1, 1.0, 0.88)", + shadowStrength = 1.0, + coastColor = "vec3(2.2, 0.4, 0.0)", + coastLightBoost = 0.7, + coastWidth = 36.0, + fogFactor = 0.08, + fogColor = "vec3(2.0, 0.31, 0.0)", + fogHeight = 85, + fogAbove = 0.18, + + tideRhym = { { 206, 0.25, 5*6000 } }, +} + +return conf diff --git a/common/configs/LavaMaps/Kings Assault.lua b/common/configs/LavaMaps/Kings Assault.lua new file mode 100644 index 00000000000..d411522acbc --- /dev/null +++ b/common/configs/LavaMaps/Kings Assault.lua @@ -0,0 +1,16 @@ +local conf = { + grow = 0, + colorCorrection = "vec3(1.0, 1.0, 1.0)", + coastColor = "vec3(1.0, 0.25, 0.0)", + coastLightBoost = 0.3, + fogColor = "vec3(1.5, 0.1, 0.0)", + fogFactor = 0.01, + fogHeight = 15, + fogAbove = 4.0, + fogDistortion = 2.0, + tideAmplitude = 0.3, + tidePeriod = 1000, + tideRhym = { { -1, 0.05, 5*6000 } }, +} + +return conf diff --git a/common/configs/LavaMaps/Pit of Azar.lua b/common/configs/LavaMaps/Pit of Azar.lua new file mode 100644 index 00000000000..6b4c52921c0 --- /dev/null +++ b/common/configs/LavaMaps/Pit of Azar.lua @@ -0,0 +1,23 @@ +local conf = { + level = 0, + damage = 150, + tideAmplitude = 3, + tidePeriod = 95, + diffuseEmitTex = "LuaUI/images/lava/lava7_diffuseemit.dds", + normalHeightTex = "LuaUI/images/lava/lava7_normalheight.dds", + losDarkness = 0.7, + colorCorrection = "vec3(1.1, 1.0, 0.88)", + shadowStrength = 1.0, + coastColor = "vec3(2.2, 0.4, 0.0)", + coastLightBoost = 0.7, + coastWidth = 36.0, + fogFactor = 0.02, + fogColor = "vec3(2.0, 0.31, 0.0)", + fogHeight = 35, + fogAbove = 0.18, + fogDistortion = 2.0, + uvScale = 10.0, + tideRhym = { { -1, 0.25, 5*6000 } }, +} + +return conf diff --git a/common/configs/LavaMaps/README.md b/common/configs/LavaMaps/README.md new file mode 100644 index 00000000000..fbc04655d84 --- /dev/null +++ b/common/configs/LavaMaps/README.md @@ -0,0 +1,14 @@ +### Lava Map Configuration Directory + +Place map specific lava configuration files here. + +Note the lava configuration can also be included inside the map pack in mapconfig/lava.lua (recommmended). + +The mapconfig has precedence over game provided configuration, but overrideMap can be set to true inside the file here to make it have priority. + +The game will try to find the full name with version, like "Ghenna Rising 4.0.1.lua", if not found then it will search for a configuration without the version "Ghenna Rising.lua". + +### Note for map makers + +You can just take a file from here and place it inside mapconfig/lava.lua for your map to have lava. + diff --git a/common/configs/LavaMaps/Sector 318C.lua b/common/configs/LavaMaps/Sector 318C.lua new file mode 100644 index 00000000000..8ad658a1823 --- /dev/null +++ b/common/configs/LavaMaps/Sector 318C.lua @@ -0,0 +1,28 @@ +local conf = { + grow = 0, + effectBurst = false, + level = 5, + diffuseEmitTex = "LuaUI/images/lava/lava7_diffuseemit.dds", + normalHeightTex = "LuaUI/images/lava/lava7_normalheight.dds", + colorCorrection = "vec3(0.2, 0.65, 0.03)", + --coastColor = "vec3(0.6, 0.7, 0.03)", + coastLightBoost = 0.6, + coastWidth = 60.0, + fogColor = "vec3(1.60, 0.8, 0.3)", + --coastWidth = 30.0, + lavaParallaxDepth = 8.0, + lavaParallaxOffset = 0.2, + swirlFreq = 0.008, + swirlAmp = 0.017, + uvScale = 2.2, + specularExp = 12.0, + tideAmplitude = 3, + tidePeriod = 40, + fogFactor = 0.13, + fogHeight = 36, + fogAbove = 0.1, + fogDistortion = 2.0, + tideRhym = { { 4, 0.05, 5*6000 } }, +} + +return conf diff --git a/common/configs/LavaMaps/SpeedMetal BAR.lua b/common/configs/LavaMaps/SpeedMetal BAR.lua new file mode 100644 index 00000000000..e0ea3de8be1 --- /dev/null +++ b/common/configs/LavaMaps/SpeedMetal BAR.lua @@ -0,0 +1,16 @@ +local conf = { + grow = 0, + effectBurst = false, + level = 1, + colorCorrection = "vec3(0.3, 0.1, 1.5)", + --coastWidth = 40.0, + --coastColor = "vec3(1.7, 0.02, 1.4)", + fogColor = "vec3(0.60, 0.02, 1)", + swirlFreq = 0.025, + swirlAmp = 0.003, + tideAmplitude = 3, + tidePeriod = 50, + tideRhym = { { 1, 0.05, 5*6000 } }, +} + +return conf diff --git a/common/configs/LavaMaps/Stronghold.lua b/common/configs/LavaMaps/Stronghold.lua new file mode 100644 index 00000000000..fffa4262eee --- /dev/null +++ b/common/configs/LavaMaps/Stronghold.lua @@ -0,0 +1,28 @@ +local config = { + grow = 0, + effectBurst = false, + level = 5, + diffuseEmitTex = "LuaUI/images/lava/lava7_diffuseemit.dds", + normalHeightTex = "LuaUI/images/lava/lava7_normalheight.dds", + colorCorrection = "vec3(0.2, 0.65, 0.03)", + --coastColor = "vec3(0.6, 0.7, 0.03)", + coastLightBoost = 0.6, + coastWidth = 60.0, + fogColor = "vec3(1.60, 0.8, 0.3)", + --coastWidth = 30.0, + lavaParallaxDepth = 8.0, + lavaParallaxOffset = 0.2, + swirlFreq = 0.008, + swirlAmp = 0.017, + uvScale = 2.2, + specularExp = 12.0, + tideAmplitude = 3, + tidePeriod = 40, + fogFactor = 0.13, + fogHeight = 36, + fogAbove = 0.1, + fogDistortion = 2.0, + tideRhym = { { 4, 0.05, 5*6000 } }, +} + +return config diff --git a/common/configs/LavaMaps/Thermal Shock.lua b/common/configs/LavaMaps/Thermal Shock.lua new file mode 100644 index 00000000000..d411522acbc --- /dev/null +++ b/common/configs/LavaMaps/Thermal Shock.lua @@ -0,0 +1,16 @@ +local conf = { + grow = 0, + colorCorrection = "vec3(1.0, 1.0, 1.0)", + coastColor = "vec3(1.0, 0.25, 0.0)", + coastLightBoost = 0.3, + fogColor = "vec3(1.5, 0.1, 0.0)", + fogFactor = 0.01, + fogHeight = 15, + fogAbove = 4.0, + fogDistortion = 2.0, + tideAmplitude = 0.3, + tidePeriod = 1000, + tideRhym = { { -1, 0.05, 5*6000 } }, +} + +return conf diff --git a/common/configs/LavaMaps/To Kill The Middle.lua b/common/configs/LavaMaps/To Kill The Middle.lua new file mode 100644 index 00000000000..b0e8d2f49a8 --- /dev/null +++ b/common/configs/LavaMaps/To Kill The Middle.lua @@ -0,0 +1,22 @@ +local conf = { + level = 0, + damage = 150, + tideAmplitude = 3, + tidePeriod = 95, + diffuseEmitTex = "LuaUI/images/lava/lava7_diffuseemit.dds", + normalHeightTex = "LuaUI/images/lava/lava7_normalheight.dds", + losDarkness = 0.7, + colorCorrection = "vec3(1.1, 1.0, 0.88)", + shadowStrength = 1.0, + coastColor = "vec3(2.2, 0.4, 0.0)", + coastLightBoost = 0.7, + coastWidth = 36.0, + fogFactor = 0.08, + fogColor = "vec3(2.0, 0.31, 0.0)", + fogHeight = 85, + fogAbove = 0.18, + + tideRhym = { { -1, 0.25, 5*6000 } }, +} + +return conf diff --git a/common/configs/LavaMaps/Zed Remake.lua b/common/configs/LavaMaps/Zed Remake.lua new file mode 100644 index 00000000000..a427ca58963 --- /dev/null +++ b/common/configs/LavaMaps/Zed Remake.lua @@ -0,0 +1,16 @@ +local conf = { + grow = 0, + level = 1, + damage = 75, + uvScale = 1.5, + colorCorrection = "vec3(0.4, 0.09, 1.2)", + losDarkness = 0.8, + coastColor = "vec3(0.8, 0.03, 1.1)", + fogColor = "vec3(0.60, 0.10, 1.1)", + coastLightBoost = 1.3, + tideAmplitude = 1.5, + tidePeriod = 150, + tideRhym = { { 0, 0.3, 5*6000 } }, +} + +return conf diff --git a/init.lua b/init.lua index 1df82255ddc..3c9cd863056 100644 --- a/init.lua +++ b/init.lua @@ -26,6 +26,11 @@ local commonFunctions = { LuaIntro = true, LuaUI = true, }, + + map = { + LuaRules = true, + LuaUI = true, + }, } if commonFunctions.spring[environment] then @@ -40,6 +45,11 @@ if commonFunctions.i18n[environment] then Spring.I18N = Spring.I18N or VFS.Include("modules/i18n/i18n.lua") end + +if commonFunctions.map[environment] then + Spring.Lava = VFS.Include("modules/lava.lua") +end + -- we don't want them to run these tests for end users -- uncomment this only when working on functions in `common/tablefunctions.lua` -- VFS.Include('common/tableFunctionsTests.lua') diff --git a/luarules/configs/lavaConfig.lua b/luarules/configs/lavaConfig.lua deleted file mode 100644 index aebab539b56..00000000000 --- a/luarules/configs/lavaConfig.lua +++ /dev/null @@ -1,471 +0,0 @@ -local mapName = Game.mapName:lower() -Spring.Echo("Lava Mapname", mapName) -lavaMap = false - --- defaults: -nolavaburstcegs = false -lavaDiffuseEmitTex = "LuaUI/images/lava/lava2_diffuseemit.dds" -lavaNormalHeightTex = "LuaUI/images/lava/lava2_normalheight.dds" - -lavaLevel = 1 -- pre-game lava level -lavaGrow = 0.25 -- initial lavaGrow speed -lavaDamage = 100 -- damage per second -lavaUVscale = 2.0 -- How many times to tile the lava texture across the entire map -lavaColorCorrection = "vec3(1.0, 1.0, 1.0)" -- final colorcorrection on all lava + shore coloring -lavaLOSdarkness = 0.5 -- how much to darken the out-of-los areas of the lava plane -lavaSwirlFreq = 0.025 -- How fast the main lava texture swirls around default 0.025 -lavaSwirlAmp = 0.003 -- How much the main lava texture is swirled around default 0.003 -lavaSpecularExp = 64.0 -- the specular exponent of the lava plane -lavaShadowStrength = 0.4 -- how much light a shadowed fragment can recieve -lavaCoastWidth = 25.0 -- how wide the coast of the lava should be -lavaCoastColor = "vec3(2.0, 0.5, 0.0)" -- the color of the lava coast -lavaCoastLightBoost = 0.6 -- how much extra brightness should coastal areas get - -lavaParallaxDepth = 16.0 -- set to >0 to enable, how deep the parallax effect is -lavaParallaxOffset = 0.5 -- center of the parallax plane, from 0.0 (up) to 1.0 (down) - -lavaFogColor = "vec3(2.0, 0.5, 0.0)" -- the color of the fog light -lavaFogFactor = 0.06 -- how dense the fog is -lavaFogHeight = 20 -- how high the fog is above the lava plane -lavaFogAbove = 1.0 -- the multiplier for how much fog should be above lava fragments, ~0.2 means the lava itself gets hardly any fog, while 2.0 would mean the lava gets a lot of extra fog -lavaFogEnabled = true --if fog above lava adds light / is enabled -lavaFogDistortion = 4.0 -- lower numbers are higher distortion amounts - -lavaTideamplitude = 2 -- how much lava should rise up-down on static level -lavaTideperiod = 200 -- how much time between live rise up-down - - ---[[ EXAMPLE - -addTideRhym(HeightLevel, Speed, Delay for next TideRhym in seconds) - -if string.find(mapName, "quicksilver") then - lavaMap = true - lavaMinHeight = 137 -- minheight of map smf - otherwise will use 0 - lavaLevel = 220 - lavaGrow = 0.25 - lavaDamage = 100 - if (gadgetHandler:IsSyncedCode()) then - addTideRhym (-21, 0.25, 5*10) - addTideRhym (150, 0.25, 3) - addTideRhym (-20, 0.25, 5*10) - addTideRhym (150, 0.25, 5) - addTideRhym (-20, 1, 5*60) - addTideRhym (180, 0.5, 60) - addTideRhym (240, 0.2, 10) - end -end - -]] - -if string.find(mapName, "stronghold") then - lavaMap = true - lavaLevel = 20 - lavaGrow = 0 - - lavaDamage = 25 -- damage per second - lavaTideamplitude = 3 - lavaTideperiod = 95 - lavaDiffuseEmitTex = "LuaUI/images/lava/lava7_diffuseemit.dds" - lavaNormalHeightTex = "LuaUI/images/lava/lava7_normalheight.dds" - lavaLOSdarkness = 0.7 - lavaColorCorrection = "vec3(1.1, 1.0, 0.88)" - lavaShadowStrength = 1.0 -- how much light a shadowed fragment can recieve - lavaCoastColor = "vec3(2.2, 0.4, 0.0)" - lavaCoastLightBoost = 0.7 - lavaCoastWidth = 36.0 - lavaFogFactor = 0.08 -- how dense the fog is - lavaFogColor = "vec3(2.0, 0.31, 0.0)" - lavaFogHeight = 85 - lavaFogAbove = 0.18 - lavaUVscale = 0.5 - lavaSwirlFreq = 0.017 - lavaSwirlAmp = 0.0024 - - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (19, 0.3, 5*6000) - end - -elseif string.find(mapName, "incandescence") then - lavaMap = true - lavaLevel = 207 - lavaDamage = 150 -- damage per second - lavaTideamplitude = 3 - lavaTideperiod = 95 - lavaDiffuseEmitTex = "LuaUI/images/lava/lava7_diffuseemit.dds" - lavaNormalHeightTex = "LuaUI/images/lava/lava7_normalheight.dds" - lavaLOSdarkness = 0.7 - lavaColorCorrection = "vec3(1.1, 1.0, 0.88)" - lavaShadowStrength = 1.0 -- how much light a shadowed fragment can recieve - lavaCoastColor = "vec3(2.2, 0.4, 0.0)" - lavaCoastLightBoost = 0.7 - lavaCoastWidth = 36.0 - lavaFogFactor = 0.08 -- how dense the fog is - lavaFogColor = "vec3(2.0, 0.31, 0.0)" - lavaFogHeight = 85 - lavaFogAbove = 0.18 - - - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (206, 0.25, 5*6000) -- needs to be -1 than pre-game lava level - end - -elseif string.find(mapName, "seths ravine") then - lavaMap = false - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (208, 0.25, 5*6000) -- needs to be -1 than pre-game lava level - end - -elseif string.find(mapName, "moonq20xr2") then - lavaMap = false - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (208, 0.25, 5*6000) -- needs to be -1 than pre-game lava level - end - -elseif string.find(mapName, "ghenna") then - lavaMap = true - lavaLevel = 251 -- pre-game lava level - lavaDamage = 750 -- damage per second - lavaColorCorrection = "vec3(0.7, 0.7, 0.7)" - lavaSwirlFreq = 0.017 - lavaSwirlAmp = 0.0024 - lavaTideamplitude = 3 - lavaSpecularExp = 4.0 - lavaShadowStrength = 0.9 - lavaCoastLightBoost = 0.8 - lavaUVscale = 1.5 - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (250, 0.10, 15) -- needs to be -1 than pre-game lava level - addTideRhym (415, 0.05, 30) - addTideRhym (250, 0.10, 5*60) - addTideRhym (415, 0.05, 30) - addTideRhym (250, 0.10, 5*60) - addTideRhym (415, 0.05, 3*30) - addTideRhym (250, 0.10, 10*60) - end - -elseif string.find(mapName, "hotstepper") then - lavaMap = true - lavaLevel = 100 -- pre-game lava level - lavaDamage = 130 -- damage per second - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (90, 0.25, 5*60) -- needs to be -1 than pre-game lava level - addTideRhym (215, 0.10, 5) - addTideRhym (90, 0.25, 5*60) - addTideRhym (290, 0.15, 5) - addTideRhym (90, 0.25, 4*60) - addTideRhym (355, 0.20, 5) - addTideRhym (90, 0.25, 4*60) - addTideRhym (390, 0.20, 5) - addTideRhym (90, 0.25, 2*60) - addTideRhym (440, 0.04, 2*60) - end - -elseif string.find(mapName, "zed remake") then - lavaMap = true - lavaGrow = 0 - lavaLevel = 1 -- pre-game lava level - lavaDamage = 75 -- damage per second - lavaUVscale = 1.5 - lavaColorCorrection = "vec3(0.4, 0.09, 1.2)" - lavaLOSdarkness = 0.8 - lavaCoastColor = "vec3(0.8, 0.03, 1.1)" - lavaFogColor = "vec3(0.60, 0.10, 1.1)" - lavaCoastLightBoost = 1.3 - lavaTideamplitude = 1.5 -- how much lava should rise up-down on static level - lavaTideperiod = 150 -- how much time between live rise up-down - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (0, 0.3, 5*6000) - end - - -elseif string.find(mapName, "acidicquarry") then - lavaMap = true - lavaGrow = 0 - nolavaburstcegs = true - lavaLevel = 5 - lavaColorCorrection = "vec3(0.26, 1.0, 0.03)" - --lavaCoastColor = "vec3(0.6, 0.7, 0.03)" - lavaCoastLightBoost = 1.2 - lavaCoastWidth = 10.0 -- how wide the coast of the lava should be - lavaFogColor = "vec3(1.60, 0.8, 0.3)" - --lavaCoastWidth = 30.0 - lavaParallaxDepth = 32.0 -- set to >0 to enable, how deep the parallax effect is - lavaParallaxOffset = 0.2 -- center of the parallax plane, from 0.0 (up) to 1.0 (down) - lavaSwirlFreq = 0.008 - lavaSwirlAmp = 0.017 - lavaUVscale = 2.2 - lavaSpecularExp = 12.0 - lavaTideamplitude = 3 - lavaTideperiod = 40 - lavaFogFactor = 0.13 - lavaFogHeight = 36 - lavaFogAbove = 0.1 - lavaFogDistortion = 2.0 - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (4, 0.05, 5*6000) - end - - -elseif string.find(mapName, "speedmetal") then - lavaMap = true - lavaGrow = 0 - nolavaburstcegs = true - lavaLevel = 1 -- pre-game lava level - lavaColorCorrection = "vec3(0.3, 0.1, 1.5)" - --lavaCoastWidth = 40.0 - --lavaCoastColor = "vec3(1.7, 0.02, 1.4)" - lavaFogColor = "vec3(0.60, 0.02, 1)" - lavaSwirlFreq = 0.025 - lavaSwirlAmp = 0.003 - lavaTideamplitude = 3 - lavaTideperiod = 50 - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (1, 0.05, 5*6000) - end - -elseif string.find(mapName, "thermal shock") then - lavaMap = true - lavaGrow = 0 - lavaColorCorrection = "vec3(1.0, 1.0, 1.0)" - lavaCoastColor = "vec3(1.0, 0.25, 0.0)" - lavaCoastLightBoost = 0.3 - lavaFogColor = "vec3(1.5, 0.1, 0.0)" - lavaFogFactor = 0.01 - lavaFogHeight = 15 - lavaFogAbove = 4.0 - lavaFogDistortion = 2.0 - lavaTideamplitude = 0.3 - lavaTideperiod = 1000 - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (-1, 0.05, 5*6000) - end - -elseif string.find(mapName, "kill the middle") then - lavaMap = true - lavaLevel = 0 - lavaDamage = 150 -- damage per second - lavaTideamplitude = 3 - lavaTideperiod = 95 - lavaDiffuseEmitTex = "LuaUI/images/lava/lava7_diffuseemit.dds" - lavaNormalHeightTex = "LuaUI/images/lava/lava7_normalheight.dds" - lavaLOSdarkness = 0.7 - lavaColorCorrection = "vec3(1.1, 1.0, 0.88)" - lavaShadowStrength = 1.0 -- how much light a shadowed fragment can recieve - lavaCoastColor = "vec3(2.2, 0.4, 0.0)" - lavaCoastLightBoost = 0.7 - lavaCoastWidth = 36.0 - lavaFogFactor = 0.08 -- how dense the fog is - lavaFogColor = "vec3(2.0, 0.31, 0.0)" - lavaFogHeight = 85 - lavaFogAbove = 0.18 - - - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (-1, 0.25, 5*6000) -- needs to be -1 than pre-game lava level - end - -elseif string.find(mapName, "kings") then - lavaMap = true - lavaGrow = 0 - lavaColorCorrection = "vec3(1.0, 1.0, 1.0)" - lavaCoastColor = "vec3(1.0, 0.25, 0.0)" - lavaCoastLightBoost = 0.3 - lavaFogColor = "vec3(1.5, 0.1, 0.0)" - lavaFogFactor = 0.01 - lavaFogHeight = 15 - lavaFogAbove = 4.0 - lavaFogDistortion = 2.0 - lavaTideamplitude = 0.3 - lavaTideperiod = 1000 - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (-1, 0.05, 5*6000) - end - -elseif string.find(mapName, "forge") then - lavaMap = true - lavaLevel = 0 - lavaDamage = 150 -- damage per second - lavaTideamplitude = 3 - lavaTideperiod = 95 - lavaDiffuseEmitTex = "LuaUI/images/lava/lava7_diffuseemit.dds" - lavaNormalHeightTex = "LuaUI/images/lava/lava7_normalheight.dds" - lavaLOSdarkness = 0.7 - lavaColorCorrection = "vec3(1.1, 1.0, 0.88)" - lavaShadowStrength = 1.0 -- how much light a shadowed fragment can recieve - lavaCoastColor = "vec3(2.2, 0.4, 0.0)" - lavaCoastLightBoost = 0.7 - lavaCoastWidth = 36.0 - lavaFogFactor = 0.02 -- how dense the fog is - lavaFogColor = "vec3(2.0, 0.31, 0.0)" - lavaFogHeight = 35 - lavaFogAbove = 0.18 - - - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (-1, 0.25, 5*6000) -- needs to be -1 than pre-game lava level - end - -elseif string.find(mapName, "sector") then - lavaMap = true - lavaGrow = 0 - nolavaburstcegs = true - lavaLevel = 5 - lavaDiffuseEmitTex = "LuaUI/images/lava/lava7_diffuseemit.dds" - lavaNormalHeightTex = "LuaUI/images/lava/lava7_normalheight.dds" - lavaColorCorrection = "vec3(0.2, 0.65, 0.03)" - --lavaCoastColor = "vec3(0.6, 0.7, 0.03)" - lavaCoastLightBoost = 0.6 - lavaCoastWidth = 60.0 -- how wide the coast of the lava should be - lavaFogColor = "vec3(1.60, 0.8, 0.3)" - --lavaCoastWidth = 30.0 - lavaParallaxDepth = 8.0 -- set to >0 to enable, how deep the parallax effect is - lavaParallaxOffset = 0.2 -- center of the parallax plane, from 0.0 (up) to 1.0 (down) - lavaSwirlFreq = 0.008 - lavaSwirlAmp = 0.017 - lavaUVscale = 2.2 - lavaSpecularExp = 12.0 - lavaTideamplitude = 3 - lavaTideperiod = 40 - lavaFogFactor = 0.13 - lavaFogHeight = 36 - lavaFogAbove = 0.1 - lavaFogDistortion = 2.0 - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (4, 0.05, 5*6000) - end - -elseif string.find(mapName, "claymore") then - lavaMap = true - lavaGrow = 0 - nolavaburstcegs = true - lavaDiffuseEmitTex = "LuaUI/images/lava/lava2_diffuseemitblue.dds" - lavaColorCorrection = "vec3(0.4, 0.5, 0.4)" - lavaCoastColor = "vec3(0.24, 0.46, 0.5)" - lavaCoastLightBoost = 0.3 - lavaFogColor = "vec3(0.24, 0.46, 0.5)" - lavaFogFactor = 0.01 - lavaFogHeight = 15 - lavaFogAbove = 4.0 - lavaFogDistortion = 2.0 - lavaTideamplitude = 0.3 - lavaTideperiod = 1000 - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (-1, 0.05, 5*6000) - end - -elseif string.find(mapName, "hyperion shale") then - lavaMap = true - lavaGrow = 0 - nolavaburstcegs = true - lavaDiffuseEmitTex = "LuaUI/images/lava/lava2_diffuseemitblue.dds" - lavaColorCorrection = "vec3(1.0, 1.0, 1.0)" - lavaCoastColor = "vec3(0.0, 0.35, 0.9)" - lavaCoastLightBoost = 0.3 - lavaFogColor = "vec3(0.0, 0.3, 1.0)" - lavaFogFactor = 0.01 - lavaFogHeight = 15 - lavaFogAbove = 4.0 - lavaFogDistortion = 2.0 - lavaTideamplitude = 0.3 - lavaTideperiod = 1000 - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (-1, 0.05, 5*6000) - end - -elseif string.find(mapName, "azar") then - lavaMap = true - lavaLevel = 0 - lavaDamage = 150 -- damage per second - lavaTideamplitude = 3 - lavaTideperiod = 95 - lavaDiffuseEmitTex = "LuaUI/images/lava/lava7_diffuseemit.dds" - lavaNormalHeightTex = "LuaUI/images/lava/lava7_normalheight.dds" - lavaLOSdarkness = 0.7 - lavaColorCorrection = "vec3(1.1, 1.0, 0.88)" - lavaShadowStrength = 1.0 -- how much light a shadowed fragment can recieve - lavaCoastColor = "vec3(2.2, 0.4, 0.0)" - lavaCoastLightBoost = 0.7 - lavaCoastWidth = 36.0 - lavaFogFactor = 0.02 -- how dense the fog is - lavaFogColor = "vec3(2.0, 0.31, 0.0)" - lavaFogHeight = 35 - lavaFogAbove = 0.18 - lavaFogDistortion = 2.0 - lavaUVscale = 10.0 - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (-1, 0.25, 5*6000) -- needs to be -1 than pre-game lava level - end - -elseif string.find(mapName, "stronghold") then - lavaMap = true - lavaGrow = 0 - nolavaburstcegs = true - lavaLevel = 5 - lavaDiffuseEmitTex = "LuaUI/images/lava/lava7_diffuseemit.dds" - lavaNormalHeightTex = "LuaUI/images/lava/lava7_normalheight.dds" - lavaColorCorrection = "vec3(0.2, 0.65, 0.03)" - --lavaCoastColor = "vec3(0.6, 0.7, 0.03)" - lavaCoastLightBoost = 0.6 - lavaCoastWidth = 60.0 -- how wide the coast of the lava should be - lavaFogColor = "vec3(1.60, 0.8, 0.3)" - --lavaCoastWidth = 30.0 - lavaParallaxDepth = 8.0 -- set to >0 to enable, how deep the parallax effect is - lavaParallaxOffset = 0.2 -- center of the parallax plane, from 0.0 (up) to 1.0 (down) - lavaSwirlFreq = 0.008 - lavaSwirlAmp = 0.017 - lavaUVscale = 2.2 - lavaSpecularExp = 12.0 - lavaTideamplitude = 3 - lavaTideperiod = 40 - lavaFogFactor = 0.13 - lavaFogHeight = 36 - lavaFogAbove = 0.1 - lavaFogDistortion = 2.0 - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (4, 0.05, 5*6000) - end - -elseif Game.waterDamage > 0 and (not voidWaterMap) then -- Waterdamagemaps - keep at the very bottom - --lavaMap = true - --lavaGrow = 0 - --lavaLevel = 1 - --if isLavaGadget and isLavaGadget == "synced" then - -- addTideRhym (1, 0.25, 5*6000) - --end - - lavaMap = true - lavaGrow = 0 - nolavaburstcegs = true - lavaLevel = 1 - lavaColorCorrection = "vec3(0.15, 1.0, 0.45)" - --lavaCoastColor = "vec3(0.6, 0.7, 0.03)" - lavaCoastLightBoost = 0.5 - lavaCoastWidth = 16.0 -- how wide the coast of the lava should be - lavaFogColor = "vec3(1.60, 0.8, 0.3)" - --lavaCoastWidth = 30.0 - lavaParallaxDepth = 24.0 -- set to >0 to enable, how deep the parallax effect is - lavaParallaxOffset = 0.15 -- center of the parallax plane, from 0.0 (up) to 1.0 (down) - lavaSwirlFreq = 0.008 - lavaSwirlAmp = 0.01 - lavaUVscale = 3 - lavaSpecularExp = 12.0 - lavaTideamplitude = 3 - lavaTideperiod = 40 - lavaFogFactor = 0.1 - lavaFogHeight = 20 - lavaFogAbove = 0.1 - lavaFogDistortion = 1 - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (4, 0.05, 5*6000) - end - -elseif Spring.GetModOptions().map_waterislava and (not voidWaterMap) then - lavaMap = true - lavaLevel = 4 - if isLavaGadget and isLavaGadget == "synced" then - addTideRhym (4, 0.05, 5*6000) - end -end - - diff --git a/luarules/gadgets/map_lava.lua b/luarules/gadgets/map_lava.lua index 5505b57a5b7..c8928c3d324 100644 --- a/luarules/gadgets/map_lava.lua +++ b/luarules/gadgets/map_lava.lua @@ -1,6 +1,6 @@ function gadget:GetInfo() return { - name = "Map Lava Gadget 2.4", + name = "Map Lava Gadget 2.5", desc = "lava", author = "knorke, Beherith, The_Yak, Anarchid, Kloot, Gajop, ivand, Damgam", date = "Feb 2011, Nov 2013, 2022!", @@ -10,44 +10,62 @@ function gadget:GetInfo() } end -tideRhym = {} -tideIndex = 1 -tideContinueFrame = 0 -lavaGrow = 0 -gameframe = 0 - -voidWaterMap = false -local success, mapinfo = pcall(VFS.Include,"mapinfo.lua") -- load mapinfo.lua confs -if success or mapinfo ~= nil then - voidWaterMap = mapinfo.voidwater -end +local lava = Spring.Lava +local lavaMap = lava.isLavaMap --_G.Game.mapSizeX = Game.mapSizeX --_G.Game.mapSizeY = Game.mapSizeY -function gadget:Initialize() - if lavaMap == false then - gadgetHandler:RemoveGadget(self) - return - end - _G.frame = 0 - _G.lavaLevel = lavaLevel - _G.lavaGrow = lavaGrow - Spring.SetGameRulesParam("lavaLevel", -99999) -end +if gadgetHandler:IsSyncedCode() then -function addTideRhym (targetLevel, speed, remainTime) - local newTide = {} - newTide.targetLevel = targetLevel - newTide.speed = speed - newTide.remainTime = remainTime - table.insert (tideRhym, newTide) -end + local tideIndex = 1 + local tideContinueFrame = 0 + local gameframe = 0 + local tideRhym = {} + + local lavaLevel = lava.level + local lavaGrow = lava.grow + + -- damage is specified in health lost per second, damage is applied every DAMAGE_RATE frames + local DAMAGE_RATE = 10 -- frames + local lavaDamage = lava.damage * (DAMAGE_RATE / Game.gameSpeed) + local lavaDamageFeatures = lava.damageFeatures + if lavaDamageFeatures then + if not tonumber(lavaDamageFeatures) then + lavaDamageFeatures = 0.1 + end + lavaDamageFeatures = lavaDamageFeatures * (DAMAGE_RATE / Game.gameSpeed) + end -if gadgetHandler:IsSyncedCode() then + -- ceg effects + local lavaEffectBurst = lava.effectBurst + local lavaEffectDamage = lava.effectDamage + + -- speedups + local spAddUnitDamage = Spring.AddUnitDamage + local spDestroyFeature = Spring.DestroyFeature + local spGetAllUnits = Spring.GetAllUnits + local spGetFeatureDefID = Spring.GetFeatureDefID + local spGetFeaturePosition = Spring.GetFeaturePosition + local spGetFeatureResources = Spring.GetFeatureResources + local spGetUnitBasePosition = Spring.GetUnitBasePosition + local spGetUnitDefID = Spring.GetUnitDefID + local spSetFeatureResources = Spring.SetFeatureResources + local spSpawnCEG = Spring.SpawnCEG + local random = math.random + local min = math.min + + local function addTideRhym (targetLevel, speed, remainTime) + local newTide = {} + newTide.targetLevel = targetLevel + newTide.speed = speed + newTide.remainTime = remainTime + table.insert (tideRhym, newTide) + end - isLavaGadget = "synced" - VFS.Include("luarules/configs/lavaConfig.lua") + for _, rhym in ipairs(lava.tideRhym) do + addTideRhym(unpack(rhym)) + end function updateLava() if (lavaGrow < 0 and lavaLevel < tideRhym[tideIndex].targetLevel) @@ -76,13 +94,22 @@ if gadgetHandler:IsSyncedCode() then return math.min(math.max(x, low), high) end + function gadget:Initialize() + if lavaMap == false then + gadgetHandler:RemoveGadget(self) + return + end + _G.lavaLevel = lavaLevel + _G.lavaGrow = lavaGrow + Spring.SetGameRulesParam("lavaLevel", -99999) + end + function gadget:GameFrame (f) gameframe = f _G.lavaLevel = lavaLevel+math.sin(f/30)*0.5 --_G.lavaLevel = lavaLevel + clamp(-0.95, math.sin(f / 30), 0.95) * 0.5 --clamp to avoid jittering when sin(x) is around +-1 - _G.frame = f - if f % 10 == 0 then + if f % DAMAGE_RATE == 0 then lavaDeathCheck() end @@ -90,45 +117,45 @@ if gadgetHandler:IsSyncedCode() then lavaLevel = lavaLevel+lavaGrow Spring.SetGameRulesParam("lavaLevel", lavaLevel) - local x = math.random(1,Game.mapX*512) - local z = math.random(1,Game.mapY*512) - local y = Spring.GetGroundHeight(x,z) - if nolavaburstcegs == false then - if y < lavaLevel then - --This should be in config file to customize effects on lava plane - if f % 5 == 0 then - Spring.SpawnCEG("lavasplash", x, lavaLevel+5, z) - local r = math.random(1,2) - if r == 1 then - Spring.PlaySoundFile("lavaburst1", math.random(80,100)/100, x, y, z, 'sfx') - elseif r == 2 then - Spring.PlaySoundFile("lavaburst2", math.random(80,100)/100, x, y, z, 'sfx') + -- burst and sound effects + if f % 5 == 0 then + local mapSizeX = Game.mapX * 512 + local mapSizeY = Game.mapY * 512 + -- bursts + if lavaEffectBurst then + local x = random(1, mapSizeX) + local z = random(1, mapSizeY) + local y = Spring.GetGroundHeight(x, z) + + if y < lavaLevel then + spSpawnCEG(lavaEffectBurst, x, lavaLevel+5, z) + + local lavaEffectBurstSounds = lava.effectBurstSounds + if lavaEffectBurstSounds and #lavaEffectBurstSounds > 0 then + local soundIndex = random(1, #lavaEffectBurstSounds) + local sound = lavaEffectBurstSounds[soundIndex] + Spring.PlaySoundFile(sound[1], random(sound[2], sound[3])/100, x, y, z, 'sfx') end end end - end - if f % 5 == 0 then + -- ambient sounds + local lavaAmbientSounds = lava.ambientSounds + if lavaAmbientSounds and #lavaAmbientSounds > 0 then for i = 1,10 do - local x = math.random(1,Game.mapX*512) - local z = math.random(1,Game.mapY*512) - local y = Spring.GetGroundHeight(x,z) - if math.random(1,3) == 1 and y < lavaLevel then - local r = math.random(1,5) - if r == 1 then - Spring.PlaySoundFile("lavabubbleshort1", math.random(25,65)/100, x, y, z, 'sfx') - elseif r == 2 then - Spring.PlaySoundFile("lavabubbleshort2", math.random(25,65)/100, x, y, z, 'sfx') - elseif r == 3 then - Spring.PlaySoundFile("lavarumbleshort1", math.random(20,40)/100, x, y, z, 'sfx') - elseif r == 4 then - Spring.PlaySoundFile("lavarumbleshort2", math.random(20,40)/100, x, y, z, 'sfx') - elseif r == 5 then - Spring.PlaySoundFile("lavarumbleshort3", math.random(20,40)/100, x, y, z, 'sfx') + if random(1, 3) == 1 then + local x = random(1, mapSizeX) + local z = random(1, mapSizeY) + local y = Spring.GetGroundHeight(x,z) + if y < lavaLevel then + local soundIndex = random(1, #lavaAmbientSounds) + local sound = lavaAmbientSounds[soundIndex] + Spring.PlaySoundFile(sound[1], random(sound[2], sound[3])/100, x, y, z, 'sfx') + break end - break end end end + end -- new to use notif system -- if lavaGrow then @@ -152,44 +179,37 @@ if gadgetHandler:IsSyncedCode() then end function lavaDeathCheck () - local all_units = Spring.GetAllUnits() - for i in pairs(all_units) do - local UnitDefID = Spring.GetUnitDefID(all_units[i]) + local gaiaTeamID = Spring.GetGaiaTeamID() + local all_units = spGetAllUnits() + for _, unitID in ipairs(all_units) do + local UnitDefID = spGetUnitDefID(unitID) if not UnitDefs[UnitDefID].canFly then - x,y,z = Spring.GetUnitBasePosition(all_units[i]) - if y ~= nil then - if y and y < lavaLevel then - --This should be in config file to change damage + effects/cegs - -- local health, maxhealth = Spring.GetUnitHealth(all_units[i]) - -- Spring.AddUnitDamage (all_units[i], health - maxhealth*0.033, 0, Spring.GetGaiaTeamID(), 1) - Spring.AddUnitDamage (all_units[i], lavaDamage/3, 0, Spring.GetGaiaTeamID(), 1) - --Spring.DestroyUnit (all_units[i], true, false, Spring.GetGaiaTeamID()) - Spring.SpawnCEG("lavadamage", x, y+5, z) + x,y,z = spGetUnitBasePosition(unitID) + if y and y < lavaLevel then + spAddUnitDamage (unitID, lavaDamage, 0, gaiaTeamID, 1) + spSpawnCEG(lavaEffectDamage, x, y+5, z) + end + end + end + if lavaDamageFeatures then + local all_features = Spring.GetAllFeatures() + for _, featureID in ipairs(all_features) do + local FeatureDefID = spGetFeatureDefID(featureID) + if not FeatureDefs[FeatureDefID].geoThermal then + x,y,z = spGetFeaturePosition(featureID) + if (y and y < lavaLevel) then + local _, maxMetal, _, maxEnergy, reclaimLeft = spGetFeatureResources (featureID) + reclaimLeft = reclaimLeft - lavaDamageFeatures + if reclaimLeft <= 0 then + spDestroyFeature(featureID) + else + spSetFeatureResources(featureID, maxMetal*reclaimLeft, maxEnergy*reclaimLeft, nil, reclaimLeft) + end + spSpawnCEG(lavaEffectDamage, x, y+5, z) end end end end - -- Below is custom reclaim/damage module for wrecks/features - -- local all_features = Spring.GetAllFeatures() - -- for i in pairs(all_features) do - -- local FeatureDefID = Spring.GetFeatureDefID(all_features[i]) - -- if not FeatureDefs[FeatureDefID].geoThermal then - -- x,y,z = Spring.GetFeaturePosition(all_features[i]) - -- if (y ~= nil) then - -- if (y and y < lavaLevel) then - -- local reclaimLeft = select(5, Spring.GetFeatureResources (all_features[i])) - -- if reclaimLeft <= 0 then - -- Spring.DestroyFeature(all_features[i]) - -- Spring.SpawnCEG("lavadamage", x, y+5, z) - -- else - -- local newReclaimLeft = reclaimLeft - 0.033 - -- Spring.SetFeatureReclaim (all_features[i], newReclaimLeft) - -- Spring.SpawnCEG("lavadamage", x, y+5, z) - -- end - -- end - -- end - -- end - -- end end local DAMAGE_EXTSOURCE_WATER = -5 @@ -211,35 +231,32 @@ if gadgetHandler:IsSyncedCode() then else -- UNSYCNED - isLavaGadget = "unsynced" - VFS.Include("luarules/configs/lavaConfig.lua") - local texturesamplingmode = '' -- ':l:' causes MASSIVE load on zoom out and downsampling textures! - local lavaDiffuseEmit = texturesamplingmode .. lavaDiffuseEmitTex -- pack emissiveness into alpha channel (this is also used as heat for distortion) - local lavaNormalHeight = texturesamplingmode .. lavaNormalHeightTex -- pack height into normals alpha + local lavaDiffuseEmit = texturesamplingmode .. lava.diffuseEmitTex -- pack emissiveness into alpha channel (this is also used as heat for distortion) + local lavaNormalHeight = texturesamplingmode .. lava.normalHeightTex -- pack height into normals alpha local lavaDistortion = texturesamplingmode .. "LuaUI/images/lavadistortion.png" local lavaShader local lavaPlaneVAO - local lavalevel = lavaLevel local foglightShader - local foglightVAO - local numfoglightVerts - local foglightenabled = lavaFogEnabled - local fogheightabovelava = lavaFogHeight + local foglightenabled = lava.fogEnabled + local fogheightabovelava = lava.fogHeight local allowDeferredMapRendering = (Spring.GetConfigInt("AllowDeferredMapRendering") == 1) -- map depth buffer is required for the foglight shader pass - local tideamplitude = lavaTideamplitude - local tideperiod = lavaTideperiod - local lavatidelevel = lavaLevel + local tideamplitude = lava.tideAmplitude + local tideperiod = lava.tidePeriod + local lavatidelevel = lava.level local heatdistortx = 0 local heatdistortz = 0 + local smoothFPS = 15 local elmosPerSquare = 256 -- The resolution of the lava + + local autoreload = false -- set to true to reload the shader every time it is edited local luaShaderDir = "LuaUI/Widgets/Include/" local LuaShader = VFS.Include(luaShaderDir.."LuaShader.lua") VFS.Include(luaShaderDir.."instancevbotable.lua") -- we are only gonna use the plane maker func of this @@ -248,389 +265,75 @@ else -- UNSYCNED local unifiedShaderConfig = { -- for lavaplane HEIGHTOFFSET = 2.0, -- how many elmos above the 'actual' lava height we should render, to avoid ROAM clipping artifacts - COASTWIDTH = lavaCoastWidth, -- how wide the coast of the lava should be - WORLDUVSCALE = lavaUVscale, -- How many times to tile the lava texture across the entire map - COASTCOLOR = lavaCoastColor, -- the color of the lava coast - SPECULAREXPONENT = lavaSpecularExp, -- the specular exponent of the lava plane + COASTWIDTH = lava.coastWidth, -- how wide the coast of the lava should be + WORLDUVSCALE = lava.uvScale, -- How many times to tile the lava texture across the entire map + COASTCOLOR = lava.coastColor, -- the color of the lava coast + SPECULAREXPONENT = lava.specularExp, -- the specular exponent of the lava plane SPECULARSTRENGTH = 1.0, -- The peak brightness of specular highlights - LOSDARKNESS = lavaLOSdarkness, -- how much to darken the out-of-los areas of the lava plane - SHADOWSTRENGTH = lavaShadowStrength, -- how much light a shadowed fragment can recieve + LOSDARKNESS = lava.losDarkness, -- how much to darken the out-of-los areas of the lava plane + SHADOWSTRENGTH = lava.shadowStrength, -- how much light a shadowed fragment can recieve OUTOFMAPHEIGHT = -100, -- what value to use when we are sampling the heightmap outside of the true bounds - SWIRLFREQUENCY = lavaSwirlFreq, -- How fast the main lava texture swirls around default 0.025 - SWIRLAMPLITUDE = lavaSwirlAmp, -- How much the main lava texture is swirled around default 0.003 - PARALLAXDEPTH = lavaParallaxDepth, -- set to >0 to enable - PARALLAXOFFSET = lavaParallaxOffset, -- center of the parallax plane, from 0.0 (up) to 1.0 (down) + SWIRLFREQUENCY = lava.swirlFreq, -- How fast the main lava texture swirls around default 0.025 + SWIRLAMPLITUDE = lava.swirlAmp, -- How much the main lava texture is swirled around default 0.003 + PARALLAXDEPTH = lava.parallaxDepth, -- set to >0 to enable + PARALLAXOFFSET = lava.parallaxOffset, -- center of the parallax plane, from 0.0 (up) to 1.0 (down) GLOBALROTATEFREQUENCY = 0.0001, -- how fast the whole lava plane shifts around GLOBALROTATEAMPLIDUE = 0.05, -- how big the radius of the circle we rotate around is -- for foglight: FOGHEIGHTABOVELAVA = fogheightabovelava, -- how much higher above the lava the fog light plane is - FOGCOLOR = lavaFogColor, -- the color of the fog light - FOGFACTOR = lavaFogFactor, -- how dense the fog is - EXTRALIGHTCOAST = lavaCoastLightBoost, -- how much extra brightness should coastal areas get - FOGLIGHTDISTORTION = lavaFogDistortion, -- lower numbers are higher distortion amounts - FOGABOVELAVA = lavaFogAbove, -- the multiplier for how much fog should be above lava fragments, ~0.2 means the lava itself gets hardly any fog, while 2.0 would mean the lava gets a lot of extra fog + FOGCOLOR = lava.fogColor, -- the color of the fog light + FOGFACTOR = lava.fogFactor, -- how dense the fog is + EXTRALIGHTCOAST = lava.coastLightBoost, -- how much extra brightness should coastal areas get + FOGLIGHTDISTORTION = lava.fogDistortion, -- lower numbers are higher distortion amounts + FOGABOVELAVA = lava.fogAbove, -- the multiplier for how much fog should be above lava fragments, ~0.2 means the lava itself gets hardly any fog, while 2.0 would mean the lava gets a lot of extra fog -- for both: - SWIZZLECOLORS = 'fragColor.rgb = (fragColor.rgb * '..lavaColorCorrection..').rgb;', -- yes you can swap around and weight color channels, right after final color, default is 'rgb' - } - - - local lavaVSSrc = [[ - #version 420 - #extension GL_ARB_uniform_buffer_object : require - #extension GL_ARB_shader_storage_buffer_object : require - #extension GL_ARB_shading_language_420pack: require - #line 10000 - layout (location = 0) in vec2 planePos; - - uniform float lavaHeight; - - out DataVS { - vec4 worldPos; - vec4 worldUV; - float inboundsness; - vec4 randpervertex; - }; - //__DEFINES__ - //__ENGINEUNIFORMBUFFERDEFS__ - - #line 11000 - - vec2 inverseMapSize = 1.0 / mapSize.xy; - - float rand(vec2 co){ // a pretty crappy random function - return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453); - } - - void main() { - // mapSize.xy is the actual map size, - //place the vertices into the world: - worldPos.y = lavaHeight; - worldPos.w = 1.0; - worldPos.xz = (1.5 * planePos +0.5) * mapSize.xy; - - // pass the world-space UVs out - float mapratio = mapSize.y / mapSize.x; - worldUV.xy = (1.5 * planePos +0.5); - worldUV.y *= mapratio; - - float gametime = (timeInfo.x + timeInfo.w) * SWIRLFREQUENCY; - - randpervertex = vec4(rand(worldPos.xz), rand(worldPos.xz * vec2(17.876234, 9.283)), rand(worldPos.xz + gametime + 2.0), rand(worldPos.xz + gametime + 3.0)); - worldUV.zw = sin(randpervertex.xy + gametime * (0.5 + randpervertex.xy)); - - // global rotatemove, has 2 params, globalrotateamplitude, globalrotatefrequency - // Spin the whole texture around slowly - float worldRotTime = (timeInfo.x + timeInfo.w) ; - worldUV.xy += vec2( sin(worldRotTime * GLOBALROTATEFREQUENCY), cos(worldRotTime * GLOBALROTATEFREQUENCY)) * GLOBALROTATEAMPLIDUE; - - // -- MAP OUT OF BOUNDS - vec2 mymin = min(worldPos.xz, mapSize.xy - worldPos.xz) * inverseMapSize; - inboundsness = min(mymin.x, mymin.y); - - // Assign world position: - gl_Position = cameraViewProj * worldPos; - } - ]] - - local lavaFSSrc = [[ - #version 330 - #extension GL_ARB_uniform_buffer_object : require - #extension GL_ARB_shading_language_420pack: require - - #line 20000 - - uniform float lavaHeight; - uniform float heatdistortx; - uniform float heatdistortz; - - uniform sampler2D heightmapTex; - uniform sampler2D lavaDiffuseEmit; - uniform sampler2D lavaNormalHeight; - uniform sampler2D lavaDistortion; - uniform sampler2DShadow shadowTex; - uniform sampler2D infoTex; - - in DataVS { - vec4 worldPos; - vec4 worldUV; - float inboundsness; - vec4 randpervertex; - }; - - //__ENGINEUNIFORMBUFFERDEFS__ - //__DEFINES__ - - vec2 inverseMapSize = 1.0 / mapSize.xy; - - float heightAtWorldPos(vec2 w){ - // Some texel magic to make the heightmap tex perfectly align: - const vec2 heightmaptexel = vec2(8.0, 8.0); - w += vec2(-8.0, -8.0) * (w * inverseMapSize) + vec2(4.0, 4.0) ; - - vec2 uvhm = clamp(w, heightmaptexel, mapSize.xy - heightmaptexel); - uvhm = uvhm * inverseMapSize; - - return texture(heightmapTex, uvhm, 0.0).x; - } - - out vec4 fragColor; - - #line 22000 - - - void main() { - - vec4 camPos = cameraViewInv[3]; - vec3 worldtocam = camPos.xyz - worldPos.xyz; - - // Sample emissive as heat indicator here for later displacement - vec4 nodiffuseEmit = texture(lavaDiffuseEmit, worldUV.xy * WORLDUVSCALE ); - - vec2 rotatearoundvertices = worldUV.zw * SWIRLAMPLITUDE; - - float localheight = OUTOFMAPHEIGHT ; - if (inboundsness > 0) - localheight = heightAtWorldPos(worldPos.xz); - - if (localheight > lavaHeight - HEIGHTOFFSET ) discard; - - // Calculate how far the fragment is from the coast - float coastfactor = clamp((localheight-lavaHeight + COASTWIDTH + HEIGHTOFFSET) * (1.0 / COASTWIDTH), 0.0, 1.0); - - // this is ramp function that ramps up for 90% of the coast, then ramps down at the last 10% of coastwidth - if (coastfactor > 0.90) - {coastfactor = 9*( 1.0 - coastfactor); - coastfactor = pow(coastfactor/0.9, 1.0); - }else{ - coastfactor = pow(coastfactor/0.9, 3.0); - } - - // Sample shadow map for shadow factor: - vec4 shadowVertexPos = shadowView * vec4(worldPos.xyz,1.0); - shadowVertexPos.xy += vec2(0.5); - float shadow = clamp(textureProj(shadowTex, shadowVertexPos), 0.0, 1.0); - - // Sample LOS texture for LOS, and scale it into a sane range - vec2 losUV = clamp(worldPos.xz, vec2(0.0), mapSize.xy ) / mapSize.zw; - float losTexSample = dot(vec3(0.33), texture(infoTex, losUV).rgb) ; // lostex is PO2 - losTexSample = clamp(losTexSample * 4.0 - 1.0, LOSDARKNESS, 1.0); - if (inboundsness < 0.0) losTexSample = 1.0; - - // We shift the distortion texture camera-upwards according to the uniforms that got passed in - vec2 camshift = vec2(heatdistortx, heatdistortz) * 0.001; - vec4 distortionTexture = texture(lavaDistortion, (worldUV.xy + camshift) * 45.2) ; - - vec2 distortion = distortionTexture.xy * 0.2 * 0.02; - distortion.xy *= clamp(nodiffuseEmit.a * 0.5 + coastfactor, 0.2, 2.0); - - vec2 diffuseNormalUVs = worldUV.xy * WORLDUVSCALE + distortion.xy + rotatearoundvertices; - vec4 normalHeight = texture(lavaNormalHeight, diffuseNormalUVs); - - // Perform optional parallax mapping - #if (PARALLAXDEPTH > 0 ) - vec3 viewvec = normalize(worldtocam * -1.0); - float pdepth = PARALLAXDEPTH * (PARALLAXOFFSET - normalHeight.a ) * (1.0 - coastfactor); - diffuseNormalUVs += pdepth * viewvec.xz * 0.002; - normalHeight = texture(lavaNormalHeight, diffuseNormalUVs); - #endif - - vec4 diffuseEmit = texture(lavaDiffuseEmit , diffuseNormalUVs); - - fragColor.rgba = diffuseEmit; - - // Calculate lighting based on normal map - vec3 fragNormal = (normalHeight.xzy * 2.0 -1.0); - fragNormal.z = -1 * fragNormal.z; // for some goddamned reason Z(G) is inverted again - fragNormal = normalize(fragNormal); - float lightamount = clamp(dot(sunDir.xyz, fragNormal), 0.2, 1.0) * max(0.5,shadow); - fragColor.rgb *= lightamount; - - fragColor.rgb += COASTCOLOR * coastfactor; - - // Specular Color - vec3 reflvect = reflect(normalize(-1.0 * sunDir.xyz), normalize(fragNormal)); - float specular = clamp(pow(dot(normalize(worldtocam), normalize(reflvect)), SPECULAREXPONENT), 0.0, SPECULARSTRENGTH) * shadow; - fragColor.rgb += fragColor.rgb * specular; - - fragColor.rgb += fragColor.rgb * (diffuseEmit.a * distortion.y * 700.0); - - fragColor.rgb *= losTexSample; - - // some debugging stuff: - //fragColor.rgb = fragNormal.xzy; - //fragColor.rgb = vec3(losTexSample); - //fragColor.rgb = vec3(shadow); - //fragColor.rgb = distortionTexture.rgb ; - //fragColor.rg = worldUV.zw ; - //fragColor.rgba *= vec4(fract(hmap*0.05)); - //fragColor.rgb = vec3(randpervertex.w * 0.5 + 0.5); - //fragColor.rgb = fract(4*vec3(coastfactor)); - fragColor.a = 1.0; - fragColor.a = clamp( inboundsness * 2.0 +2.0, 0.0, 1.0); - SWIZZLECOLORS + SWIZZLECOLORS = 'fragColor.rgb = (fragColor.rgb * '..lava.colorCorrection..').rgb;', -- yes you can swap around and weight color channels, right after final color, default is 'rgb' } - ]] - - - local fogLightVSSrc = [[ - #version 420 - #extension GL_ARB_uniform_buffer_object : require - #extension GL_ARB_shader_storage_buffer_object : require - #extension GL_ARB_shading_language_420pack: require - #line 10000 - layout (location = 0) in vec2 planePos; - - uniform float lavaHeight; - - out DataVS { - vec4 worldPos; - vec4 worldUV; - float inboundsness; - noperspective vec2 v_screenUV; - }; - //__DEFINES__ - //__ENGINEUNIFORMBUFFERDEFS__ - - #line 11000 - - #define SNORM2NORM(value) (value * 0.5 + 0.5) - vec2 inverseMapSize = 1.0 / mapSize.xy; - float rand(vec2 co){ // a pretty crappy random function - return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453); + local lavaVSSrcPath = "shaders/GLSL/lava/lava.vert.glsl" + local lavaFSSrcPath = "shaders/GLSL/lava/lava.frag.glsl" + local fogLightVSSrcPath = "shaders/GLSL/lava/lava_fog_light.vert.glsl" + local fogLightFSSrcPath = "shaders/GLSL/lava/lava_fog_light.frag.glsl" + + local lavaShaderSourceCache = { + vssrcpath = lavaVSSrcPath, + fssrcpath = lavaFSSrcPath, + shaderName = "Lava Surface Shader GL4", + uniformInt = { + heightmapTex = 0, + lavaDiffuseEmit = 1, + lavaNormalHeight = 2, + lavaDistortion = 3, + shadowTex = 4, + infoTex = 5, + }, + uniformFloat = { + lavaHeight = 1, + heatdistortx = 1, + heatdistortz = 1, + }, + shaderConfig = unifiedShaderConfig, } - void main() { - // mapSize.xy is the actual map size, - //place the vertices into the world: - worldPos.y = lavaHeight; - worldPos.w = 1.0; - worldPos.xz = (1.5 * planePos +0.5) * mapSize.xy; - - // pass the world-space UVs out - float mapratio = mapSize.y / mapSize.x; - worldUV.xy = (1.5 * planePos +0.5); - worldUV.y *= mapratio; - - float gametime = (timeInfo.x + timeInfo.w) * 0.006666; - - vec4 randpervertex = vec4(rand(worldPos.xz), rand(worldPos.xz * vec2(17.876234, 9.283)), rand(worldPos.xz + gametime + 2.0), rand(worldPos.xz + gametime + 3.0)); - worldUV.zw = sin(randpervertex.xy + gametime * (0.5 + randpervertex.xy)); - - // -- MAP OUT OF BOUNDS - vec2 mymin = min(worldPos.xz, mapSize.xy - worldPos.xz) * inverseMapSize; - inboundsness = min(mymin.x, mymin.y); - - // Assign world position: - gl_Position = cameraViewProj * worldPos; - v_screenUV = SNORM2NORM(gl_Position.xy / gl_Position.w); + local fogLightShaderSourceCache = { + vssrcpath = fogLightVSSrcPath, + fssrcpath = fogLightFSSrcPath, + shaderName = "Lava Light Shader GL4", + uniformInt = { + mapDepths = 0, + modelDepths = 1, + lavaDistortion = 2, + }, + uniformFloat = { + lavaHeight = 1, + heatdistortx = 1, + heatdistortz = 1, + }, + shaderConfig = unifiedShaderConfig, } - ]] - - local foglightFSSrc = [[ - #version 330 - #extension GL_ARB_uniform_buffer_object : require - #extension GL_ARB_shading_language_420pack: require - - #line 20000 - - uniform float lavaHeight; - uniform float heatdistortx; - uniform float heatdistortz; - - uniform sampler2D mapDepths; - uniform sampler2D modelDepths; - uniform sampler2D lavaDistortion; - //uniform sampler2D mapNormals; - //uniform sampler2D modelNormals; - - in DataVS { - vec4 worldPos; - vec4 worldUV; - float inboundsness; - noperspective vec2 v_screenUV; - }; - - //__ENGINEUNIFORMBUFFERDEFS__ - //__DEFINES__ - - vec2 inverseMapSize = 1.0 / mapSize.xy; - - out vec4 fragColor; - - #line 22000 - void main() { - - vec4 camPos = cameraViewInv[3]; - - // We shift the distortion texture camera-upwards according to the uniforms that got passed in - vec2 camshift = vec2(heatdistortx, heatdistortz) * 0.01; - - //Get the fragment depth - // note that WE CANT GO LOWER THAN THE ACTUAL LAVA LEVEL! - - vec2 screenUV = clamp(v_screenUV, 1.0/(viewGeometry.xy), 1.0 - 1.0/ (viewGeometry.xy)); - - // Sample the depth buffers, and choose whichever is closer to the screen - float mapdepth = texture(mapDepths, screenUV).x; - float modeldepth = texture(modelDepths, screenUV).x; - mapdepth = min(mapdepth, modeldepth); - - // the W weight factor here is incorrect, as it comes from the depth buffers, and not the fragments own depth. - - // Convert to normalized device coordinates, and calculate inverse view projection - vec4 mapWorldPos = vec4( vec3(screenUV.xy * 2.0 - 1.0, mapdepth), 1.0); - mapWorldPos = cameraViewProjInv * mapWorldPos; - mapWorldPos.xyz = mapWorldPos.xyz/ mapWorldPos.w; // YAAAY this works! - float trueFragmentHeight = mapWorldPos.y; - - float fogAboveLava = 1.0; - - // clip mapWorldPos according to true lava height - if (mapWorldPos.y< lavaHeight - FOGHEIGHTABOVELAVA - HEIGHTOFFSET) { - // we need to make a vector from cam to fogplane position - vec3 camtofogplane = mapWorldPos.xyz - camPos.xyz; - - // and scale it to make it - camtofogplane = FOGHEIGHTABOVELAVA * camtofogplane /abs(camtofogplane.y); - mapWorldPos.xyz = worldPos.xyz + camtofogplane; - fogAboveLava = FOGABOVELAVA; - } - - // Calculate how long the vector from top of foglightplane to lava or world pos actually is - float actualfogdepth = length(mapWorldPos.xyz - worldPos.xyz) ; - float fogAmount = 1.0 - exp2(- FOGFACTOR * FOGFACTOR * actualfogdepth * 0.5); - fogAmount *= fogAboveLava; - - // sample the distortiontexture according to camera shift and scale it down - vec4 distortionTexture = texture(lavaDistortion, (worldUV.xy * 22.0 + camshift)) ; - float fogdistort = (FOGLIGHTDISTORTION + distortionTexture.x + distortionTexture.y)/ FOGLIGHTDISTORTION ; - - - // apply some distortion to the fog - fogAmount *= fogdistort; - - - // lets add some extra brigtness near the coasts, by finding the distance of the lavaplane to the coast - float disttocoast = abs(trueFragmentHeight- (lavaHeight - FOGHEIGHTABOVELAVA - HEIGHTOFFSET)); - - float extralightcoast = clamp(1.0 - disttocoast * (1.0 / COASTWIDTH), 0.0, 1.0); - extralightcoast = pow(extralightcoast, 3.0) * EXTRALIGHTCOAST; - - fogAmount += extralightcoast; - - fragColor.rgb = FOGCOLOR; - fragColor.a = fogAmount; - - // fade out the foglightplane if it is far out of bounds - fragColor.a *= clamp( inboundsness * 2.0 +2.0, 0.0, 1.0); - SWIZZLECOLORS - } - ]] - local myPlayerID = tostring(Spring.GetMyPlayerID()) function gadget:GameFrame(f) @@ -682,54 +385,17 @@ else -- UNSYCNED lavaPlaneVAO:AttachIndexBuffer(indexBuffer) - local engineUniformBufferDefs = LuaShader.GetEngineUniformBufferDefs() - lavaVSSrc = lavaVSSrc:gsub("//__ENGINEUNIFORMBUFFERDEFS__", engineUniformBufferDefs) - lavaFSSrc = lavaFSSrc:gsub("//__ENGINEUNIFORMBUFFERDEFS__", engineUniformBufferDefs) - - lavaShader = LuaShader({ - vertex = lavaVSSrc:gsub("//__DEFINES__", LuaShader.CreateShaderDefinesString(unifiedShaderConfig)), - fragment = lavaFSSrc:gsub("//__DEFINES__", LuaShader.CreateShaderDefinesString(unifiedShaderConfig)), - uniformInt = { - heightmapTex = 0, - lavaDiffuseEmit = 1, - lavaNormalHeight = 2, - lavaDistortion = 3, - shadowTex = 4, - infoTex = 5, - }, - uniformFloat = { - lavaHeight = 1, - heatdistortx = 1, - heatdistortz = 1, - }, - }, "Lava Shader") - - - fogLightVSSrc = fogLightVSSrc:gsub("//__ENGINEUNIFORMBUFFERDEFS__", engineUniformBufferDefs) - foglightFSSrc = foglightFSSrc:gsub("//__ENGINEUNIFORMBUFFERDEFS__", engineUniformBufferDefs) - foglightShader = LuaShader({ - vertex = fogLightVSSrc:gsub("//__DEFINES__", LuaShader.CreateShaderDefinesString(unifiedShaderConfig)), - fragment = foglightFSSrc:gsub("//__DEFINES__", LuaShader.CreateShaderDefinesString(unifiedShaderConfig)), - uniformInt = { - mapDepths = 0, - modelDepths = 1, - lavaDistortion = 2, - }, - uniformFloat = { - lavaHeight = 1, - heatdistortx = 1, - heatdistortz = 1, - }, - }, "FogLight shader ") - local shaderCompiled = lavaShader:Initialize() - if not shaderCompiled then + lavaShader = LuaShader.CheckShaderUpdates(lavaShaderSourceCache) + + if not lavaShader then Spring.Echo("Failed to compile Lava Shader") gadgetHandler:RemoveGadget() return end - shaderCompiled = foglightShader:Initialize() - if not shaderCompiled then + foglightShader = LuaShader.CheckShaderUpdates(fogLightShaderSourceCache) + + if not foglightShader then Spring.Echo("Failed to compile foglightShader") gadgetHandler:RemoveGadget() return @@ -742,12 +408,17 @@ else -- UNSYCNED if not isPaused then local camX, camY, camZ = Spring.GetCameraDirection() local camvlength = math.sqrt(camX*camX + camZ *camZ + 0.01) - local fps = math.max(Spring.GetFPS(), 15) - heatdistortx = heatdistortx - camX / (camvlength * fps) - heatdistortz = heatdistortz - camZ / (camvlength * fps) + smoothFPS = 0.9 * smoothFPS + 0.1 * math.max(Spring.GetFPS(), 15) + heatdistortx = heatdistortx - camX / (camvlength * smoothFPS) + heatdistortz = heatdistortz - camZ / (camvlength * smoothFPS) end --Spring.Echo(camX, camZ, heatdistortx, heatdistortz,gameSpeed, isPaused) + if autoreload then + lavaShader = LuaShader.CheckShaderUpdates(lavaShaderSourceCache) or lavaShader + foglightShader = LuaShader.CheckShaderUpdates(fogLightShaderSourceCache) or foglightShader + end + lavaShader:Activate() lavaShader:SetUniform("lavaHeight",lavatidelevel) lavaShader:SetUniform("heatdistortx",heatdistortx) diff --git a/luaui/Widgets/cmd_context_build.lua b/luaui/Widgets/cmd_context_build.lua index 0cb7ea107e2..4e4b3967dd9 100644 --- a/luaui/Widgets/cmd_context_build.lua +++ b/luaui/Widgets/cmd_context_build.lua @@ -1,7 +1,7 @@ local voidWater = false local waterLevel = Spring.GetModOptions().map_waterlevel -local waterIsLava = Spring.GetModOptions().map_waterislava +local waterIsLava = Spring.Lava.isLavaMap local minHeight, _, _, _ = Spring.GetGroundExtremes() local success, mapinfo = pcall(VFS.Include,"mapinfo.lua") -- load mapinfo.lua confs if success and mapinfo then diff --git a/luaui/Widgets/gui_top_bar.lua b/luaui/Widgets/gui_top_bar.lua index 245546c5712..98c35c8bd73 100644 --- a/luaui/Widgets/gui_top_bar.lua +++ b/luaui/Widgets/gui_top_bar.lua @@ -60,7 +60,7 @@ local xPos = math_floor(vsx * relXpos) local currentWind = 0 local gameStarted = (Spring.GetGameFrame() > 0) local displayComCounter = false -local displayTidalSpeed = not (Spring.GetModOptions().map_waterislava or Game.waterDamage > 0) +local displayTidalSpeed = not Spring.Lava.isLavaMap local updateTextClock = os.clock() local glTranslate = gl.Translate diff --git a/luaui/Widgets/map_edge_extension2.lua b/luaui/Widgets/map_edge_extension2.lua index 7bb28147c9a..cef523809bc 100644 --- a/luaui/Widgets/map_edge_extension2.lua +++ b/luaui/Widgets/map_edge_extension2.lua @@ -520,8 +520,7 @@ function widget:Initialize() widgetHandler:RemoveWidget() return end - VFS.Include("luarules/configs/lavaConfig.lua") - if lavaMap == true then + if Spring.Lava.isLavaMap == true then widgetHandler:RemoveWidget(self) end diff --git a/modules/lava.lua b/modules/lava.lua new file mode 100644 index 00000000000..1646673d02d --- /dev/null +++ b/modules/lava.lua @@ -0,0 +1,239 @@ +local mapName = Game.mapName +Spring.Echo("Lava Mapname", mapName) + +local MAP_CONFIG_PATH = "mapconfig/lava.lua" +local GAME_CONFIG_DIR = "common/configs/LavaMaps/" + +local voidWaterMap = false + +local success, mapinfo = pcall(VFS.Include, "mapinfo.lua") -- load mapinfo.lua confs +if success or mapinfo ~= nil then + voidWaterMap = mapinfo.voidwater +end + +local isLavaMap = false + +---------------------------------------- +-- Defaults: + +local diffuseEmitTex = "LuaUI/images/lava/lava2_diffuseemit.dds" +local normalHeightTex = "LuaUI/images/lava/lava2_normalheight.dds" + +local level = 1 -- pre-game lava level +local grow = 0.25 -- initial lava grow speed +local damage = 100 -- damage per second or health proportion (0-1) +local damageFeatures = false -- Lava also damages features when set, if set to float, it's proportional damage per second (0 to 1), if set to true sets default of 0.1 +local uvScale = 2.0 -- How many times to tile the lava texture across the entire map +local colorCorrection = "vec3(1.0, 1.0, 1.0)" -- final colorcorrection on all lava + shore coloring +local losDarkness = 0.5 -- how much to darken the out-of-los areas of the lava plane +local swirlFreq = 0.025 -- How fast the main lava texture swirls around default 0.025 +local swirlAmp = 0.003 -- How much the main lava texture is swirled around default 0.003 +local specularExp = 64.0 -- the specular exponent of the lava plane +local shadowStrength = 0.4 -- how much light a shadowed fragment can recieve +local coastWidth = 25.0 -- how wide the coast of the lava should be +local coastColor = "vec3(2.0, 0.5, 0.0)" -- the color of the lava coast +local coastLightBoost = 0.6 -- how much extra brightness should coastal areas get + +local parallaxDepth = 16.0 -- set to >0 to enable, how deep the parallax effect is +local parallaxOffset = 0.5 -- center of the parallax plane, from 0.0 (up) to 1.0 (down) + +local fogColor = "vec3(2.0, 0.5, 0.0)" -- the color of the fog light +local fogFactor = 0.06 -- how dense the fog is +local fogHeight = 20 -- how high the fog is above the lava plane +local fogAbove = 1.0 -- the multiplier for how much fog should be above lava fragments, ~0.2 means the lava itself gets hardly any fog, while 2.0 would mean the lava gets a lot of extra fog +local fogEnabled = true --if fog above lava adds light / is enabled +local fogDistortion = 4.0 -- lower numbers are higher distortion amounts + +local tideAmplitude = 2 -- how much lava should rise up-down on static level +local tidePeriod = 200 -- how much time between live rise up-down + +local effectDamage = "lavadamage" -- damage ceg effect +local effectBurst = "lavasplash" -- burst ceg effect, set to false to disable +-- sound arrays: always rows with {soundid, minVolume, maxVolume} +local effectBurstSounds = { {"lavaburst1", 80, 100}, {"lavaburst2", 80, 100} } -- array of sounds to use for bursts, false or empty array will disable sounds +local ambientSounds = { {"lavabubbleshort1", 25, 65}, -- ambient sounds, set ambientSounds = false to disable + {"lavabubbleshort2", 25, 65}, + {"lavarumbleshort1", 20, 40}, + {"lavarumbleshort2", 20, 40}, + {"lavarumbleshort3", 20, 40} } + +--- Tide animation scenes +--- each row is: { HeightLevel, Speed, Delay for next TideRhym in seconds } +--- first element needs to be -1 than pre-game lava level when present +local tideRhym = {} + + +---------------------------------------- +-- Helper methods + +local function trimMapVersion(mapName) + -- Trims version from the end of the map name. + -- find last space before version (version is numbers with dots, possibly preceded by v or V) + local lastSpace = mapName:match'^.*()\ [vV]*[%d%.]+' + if not lastSpace then return mapName end + return string.sub(mapName, 1, lastSpace - 1) +end + +local function gameConfigPath(mapName) + return GAME_CONFIG_DIR .. mapName .. ".lua" +end + +local function getLavaConfig(mapName) + if voidWaterMap then return end + -- Get lava config for map. + -- mapConfig has preference over gameConfig, unless game sets 'overrideMap' + local gameConfig, mapConfig + if mapName then + -- Look for full name (with version), and otherwise try with trimmed version. + local mapNameNoVersion = trimMapVersion(mapName) + if VFS.FileExists(gameConfigPath(mapName)) then + gameConfig = VFS.Include(gameConfigPath(mapName)) + Spring.Log('Lava', LOG.INFO, "Loaded map config for", mapName) + elseif mapName ~= mapNameNoVersion and VFS.FileExists(gameConfigPath(mapNameNoVersion)) then + gameConfig = VFS.Include(gameConfigPath(mapNameNoVersion)) + Spring.Log('Lava', LOG.INFO, "Loaded map config for", mapNameNoVersion) + end + end + if VFS.FileExists(MAP_CONFIG_PATH) then + mapConfig = VFS.Include(MAP_CONFIG_PATH) + Spring.Log('Lava', LOG.INFO, "Loaded map config for", mapNameNoVersion) + end + if mapConfig and gameConfig and gameConfig.overrideMap then + -- allow gameconfig to override map config when 'overrideMap' is set + mapConfig = gameConfig + Spring.Log('Lava', LOG.INFO, "Game config overrides map") + end + return mapConfig or gameConfig +end + +local function applyConfig(lavaConfig) + isLavaMap = true + + diffuseEmitTex = lavaConfig.diffuseEmitTex or diffuseEmitTex + normalHeightTex = lavaConfig.normalHeightTex or normalHeightTex + + level = lavaConfig.level or level + grow = lavaConfig.grow or grow + damage = lavaConfig.damage or damage + if lavaConfig.damageFeatures ~= nil then + damageFeatures = lavaConfig.damageFeatures + end + uvScale = lavaConfig.uvScale or uvScale + colorCorrection = lavaConfig.colorCorrection or colorCorrection + losDarkness = lavaConfig.losDarkness or losDarkness + swirlFreq = lavaConfig.swirlFreq or swirlFreq + swirlAmp = lavaConfig.swirlAmp or swirlAmp + specularExp = lavaConfig.specularExp or specularExp + shadowStrength = lavaConfig.shadowStrength or shadowStrength + coastWidth = lavaConfig.coastWidth or coastWidth + coastColor = lavaConfig.coastColor or coastColor + coastLightBoost = lavaConfig.coastLightBoost or coastLightBoost + + parallaxDepth = lavaConfig.parallaxDepth or parallaxDepth + parallaxOffset = lavaConfig.parallaxOffset or parallaxOffset + + fogColor = lavaConfig.fogColor or fogColor + fogFactor = lavaConfig.forFactor or fogFactor + fogHeight = lavaConfig.fogHeight or fogHeight + fogAbove = lavaConfig.fogAbove or fogAbove + if lavaConfig.fogEnabled ~= nil then + fogEnabled = lavaConfig.fogEnabled + end + fogDistortion = lavaConfig.fogDistortion or fogDistortion + + tideAmplitude = lavaConfig.tideAmplitude or tideAmplitude + tidePeriod = lavaConfig.tidePeriod or tidePeriod + tideRhym = lavaConfig.tideRhym or tideRhym + effectDamage = lavaConfig.effectDamage or effectDamage + if lavaConfig.effectBurst ~= nil then + effectBurst = lavaConfig.effectBurst + end + effectBurstSounds = lavaConfig.effectBurstSounds or effectBurstSounds + if lavaConfig.ambientSounds ~= nil then + ambientSounds = lavaConfig.ambientSounds + end +end + + +---------------------------------------- +-- Process config + +local mapLavaConfig = getLavaConfig(mapName) + +if mapLavaConfig and (not voidWaterMap) then + applyConfig(mapLavaConfig) + +elseif Game.waterDamage > 0 and (not voidWaterMap) then -- Waterdamagemaps - keep at the very bottom + isLavaMap = true + grow = 0 + effectBurst = false + level = 1 + colorCorrection = "vec3(0.15, 1.0, 0.45)" + --coastColor = "vec3(0.6, 0.7, 0.03)" + coastLightBoost = 0.5 + coastWidth = 16.0 -- how wide the coast of the lava should be + fogColor = "vec3(1.60, 0.8, 0.3)" + --coastWidth = 30.0 + lavaParallaxDepth = 24.0 -- set to >0 to enable, how deep the parallax effect is + lavaParallaxOffset = 0.15 -- center of the parallax plane, from 0.0 (up) to 1.0 (down) + swirlFreq = 0.008 + swirlAmp = 0.01 + uvScale = 3 + specularExp = 12.0 + tideAmplitude = 3 + tidePeriod = 40 + fogFactor = 0.1 + fogHeight = 20 + fogAbove = 0.1 + fogDistortion = 1 + tideRhym = { { 4, 0.05, 5*6000 } } + --tideRhym = { { 1, 0.25, 5*6000 } } + +elseif Spring.GetModOptions().map_waterislava and (not voidWaterMap) then + isLavaMap = true + level = 4 + tideRhym = { { 4, 0.05, 5*6000 } } +end + + +return { + isLavaMap = isLavaMap, + + diffuseEmitTex = diffuseEmitTex, + normalHeightTex = normalHeightTex, + + level = level, + grow = grow, + damage = damage, + damageFeatures = damageFeatures, + uvScale = uvScale, + colorCorrection = colorCorrection, + losDarkness = losDarkness, + swirlFreq = swirlFreq, + swirlAmp = swirlAmp, + specularExp = specularExp, + shadowStrength = shadowStrength, + coastWidth = coastWidth, + coastColor = coastColor, + coastLightBoost = coastLightBoost, + + lavaParallaxDepth = lavaParallaxDepth, + lavaParallaxOffset = lavaParallaxOffset, + + fogColor = fogColor, + fogFactor = fogFactor, + fogHeight = fogHeight, + fogAbove = fogAbove, + fogEnabled = fogEnabled, + fogDistortion = fogDistortion, + + tideAmplitude = tideAmplitude, + tidePeriod = tidePeriod, + + tideRhym = tideRhym, + + effectDamage = effectDamage, + effectBurst = effectBurst, + effectBurstSounds = effectBurstSounds, + ambientSounds = ambientSounds, +} diff --git a/shaders/GLSL/lava/lava.frag.glsl b/shaders/GLSL/lava/lava.frag.glsl new file mode 100644 index 00000000000..205e4f41203 --- /dev/null +++ b/shaders/GLSL/lava/lava.frag.glsl @@ -0,0 +1,138 @@ +#version 330 +#extension GL_ARB_uniform_buffer_object : require +#extension GL_ARB_shading_language_420pack: require + +// This shader is Copyright (c) 2024 Beherith (mysterme@gmail.com) and licensed under the MIT License + +#line 20000 + +uniform float lavaHeight; +uniform float heatdistortx; +uniform float heatdistortz; + +uniform sampler2D heightmapTex; +uniform sampler2D lavaDiffuseEmit; +uniform sampler2D lavaNormalHeight; +uniform sampler2D lavaDistortion; +uniform sampler2DShadow shadowTex; +uniform sampler2D infoTex; + +in DataVS { + vec4 worldPos; + vec4 worldUV; + float inboundsness; + vec4 randpervertex; +}; + +//__ENGINEUNIFORMBUFFERDEFS__ +//__DEFINES__ + +vec2 inverseMapSize = 1.0 / mapSize.xy; + +float heightAtWorldPos(vec2 w){ + // Some texel magic to make the heightmap tex perfectly align: + const vec2 heightmaptexel = vec2(8.0, 8.0); + w += vec2(-8.0, -8.0) * (w * inverseMapSize) + vec2(4.0, 4.0) ; + + vec2 uvhm = clamp(w, heightmaptexel, mapSize.xy - heightmaptexel); + uvhm = uvhm * inverseMapSize; + + return texture(heightmapTex, uvhm, 0.0).x; +} + +out vec4 fragColor; + +#line 22000 + + +void main() { + + vec4 camPos = cameraViewInv[3]; + vec3 worldtocam = camPos.xyz - worldPos.xyz; + + // Sample emissive as heat indicator here for later displacement + vec4 nodiffuseEmit = texture(lavaDiffuseEmit, worldUV.xy * WORLDUVSCALE ); + + vec2 rotatearoundvertices = worldUV.zw * SWIRLAMPLITUDE; + + float localheight = OUTOFMAPHEIGHT ; + if (inboundsness > 0) + localheight = heightAtWorldPos(worldPos.xz); + + if (localheight > lavaHeight - HEIGHTOFFSET ) discard; + + // Calculate how far the fragment is from the coast + float coastfactor = clamp((localheight-lavaHeight + COASTWIDTH + HEIGHTOFFSET) * (1.0 / COASTWIDTH), 0.0, 1.0); + + // this is ramp function that ramps up for 90% of the coast, then ramps down at the last 10% of coastwidth + if (coastfactor > 0.90) + {coastfactor = 9*( 1.0 - coastfactor); + coastfactor = pow(coastfactor/0.9, 1.0); + }else{ + coastfactor = pow(coastfactor/0.9, 3.0); + } + + // Sample shadow map for shadow factor: + vec4 shadowVertexPos = shadowView * vec4(worldPos.xyz,1.0); + shadowVertexPos.xy += vec2(0.5); + float shadow = clamp(textureProj(shadowTex, shadowVertexPos), 0.0, 1.0); + + // Sample LOS texture for LOS, and scale it into a sane range + vec2 losUV = clamp(worldPos.xz, vec2(0.0), mapSize.xy ) / mapSize.zw; + float losTexSample = dot(vec3(0.33), texture(infoTex, losUV).rgb) ; // lostex is PO2 + losTexSample = clamp(losTexSample * 4.0 - 1.0, LOSDARKNESS, 1.0); + if (inboundsness < 0.0) losTexSample = 1.0; + + // We shift the distortion texture camera-upwards according to the uniforms that got passed in + vec2 camshift = vec2(heatdistortx, heatdistortz) * 0.001; + vec4 distortionTexture = texture(lavaDistortion, (worldUV.xy + camshift) * 45.2) ; + + vec2 distortion = distortionTexture.xy * 0.2 * 0.02; + distortion.xy *= clamp(nodiffuseEmit.a * 0.5 + coastfactor, 0.2, 2.0); + + vec2 diffuseNormalUVs = worldUV.xy * WORLDUVSCALE + distortion.xy + rotatearoundvertices; + vec4 normalHeight = texture(lavaNormalHeight, diffuseNormalUVs); + + // Perform optional parallax mapping + #if (PARALLAXDEPTH > 0 ) + vec3 viewvec = normalize(worldtocam * -1.0); + float pdepth = PARALLAXDEPTH * (PARALLAXOFFSET - normalHeight.a ) * (1.0 - coastfactor); + diffuseNormalUVs += pdepth * viewvec.xz * 0.002; + normalHeight = texture(lavaNormalHeight, diffuseNormalUVs); + #endif + + vec4 diffuseEmit = texture(lavaDiffuseEmit , diffuseNormalUVs); + + fragColor.rgba = diffuseEmit; + + // Calculate lighting based on normal map + vec3 fragNormal = (normalHeight.xzy * 2.0 -1.0); + fragNormal.z = -1 * fragNormal.z; // for some goddamned reason Z(G) is inverted again + fragNormal = normalize(fragNormal); + float lightamount = clamp(dot(sunDir.xyz, fragNormal), 0.2, 1.0) * max(0.5,shadow); + fragColor.rgb *= lightamount; + + fragColor.rgb += COASTCOLOR * coastfactor; + + // Specular Color + vec3 reflvect = reflect(normalize(-1.0 * sunDir.xyz), normalize(fragNormal)); + float specular = clamp(pow(dot(normalize(worldtocam), normalize(reflvect)), SPECULAREXPONENT), 0.0, SPECULARSTRENGTH) * shadow; + fragColor.rgb += fragColor.rgb * specular; + + fragColor.rgb += fragColor.rgb * (diffuseEmit.a * distortion.y * 700.0); + + fragColor.rgb *= losTexSample; + + // some debugging stuff: + //fragColor.rgb = fragNormal.xzy; + //fragColor.rgb = vec3(losTexSample); + //fragColor.rgb = vec3(shadow); + //fragColor.rgb = distortionTexture.rgb ; + //fragColor.rg = worldUV.zw ; + //fragColor.rgba *= vec4(fract(hmap*0.05)); + //fragColor.rgb = vec3(randpervertex.w * 0.5 + 0.5); + //fragColor.rgb = fract(4*vec3(coastfactor)); + fragColor.a = 1.0; + fragColor.a = clamp( inboundsness * 2.0 +2.0, 0.0, 1.0); + SWIZZLECOLORS +} diff --git a/shaders/GLSL/lava/lava.vert.glsl b/shaders/GLSL/lava/lava.vert.glsl new file mode 100644 index 00000000000..fa393eeade9 --- /dev/null +++ b/shaders/GLSL/lava/lava.vert.glsl @@ -0,0 +1,58 @@ +#version 420 +#extension GL_ARB_uniform_buffer_object : require +#extension GL_ARB_shader_storage_buffer_object : require +#extension GL_ARB_shading_language_420pack: require + +// This shader is Copyright (c) 2024 Beherith (mysterme@gmail.com) and licensed under the MIT License + +#line 10000 +layout (location = 0) in vec2 planePos; + +uniform float lavaHeight; + +out DataVS { + vec4 worldPos; + vec4 worldUV; + float inboundsness; + vec4 randpervertex; +}; +//__DEFINES__ +//__ENGINEUNIFORMBUFFERDEFS__ + +#line 11000 + +vec2 inverseMapSize = 1.0 / mapSize.xy; + +float rand(vec2 co){ // a pretty crappy random function + return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453); +} + +void main() { + // mapSize.xy is the actual map size, + //place the vertices into the world: + worldPos.y = lavaHeight; + worldPos.w = 1.0; + worldPos.xz = (1.5 * planePos +0.5) * mapSize.xy; + + // pass the world-space UVs out + float mapratio = mapSize.y / mapSize.x; + worldUV.xy = (1.5 * planePos +0.5); + worldUV.y *= mapratio; + + float gametime = (timeInfo.x + timeInfo.w) * SWIRLFREQUENCY; + + randpervertex = vec4(rand(worldPos.xz), rand(worldPos.xz * vec2(17.876234, 9.283)), rand(worldPos.xz + gametime + 2.0), rand(worldPos.xz + gametime + 3.0)); + worldUV.zw = sin(randpervertex.xy + gametime * (0.5 + randpervertex.xy)); + + // global rotatemove, has 2 params, globalrotateamplitude, globalrotatefrequency + // Spin the whole texture around slowly + float worldRotTime = (timeInfo.x + timeInfo.w) ; + worldUV.xy += vec2( sin(worldRotTime * GLOBALROTATEFREQUENCY), cos(worldRotTime * GLOBALROTATEFREQUENCY)) * GLOBALROTATEAMPLIDUE; + + // -- MAP OUT OF BOUNDS + vec2 mymin = min(worldPos.xz, mapSize.xy - worldPos.xz) * inverseMapSize; + inboundsness = min(mymin.x, mymin.y); + + // Assign world position: + gl_Position = cameraViewProj * worldPos; +} diff --git a/shaders/GLSL/lava/lava_fog_light.frag.glsl b/shaders/GLSL/lava/lava_fog_light.frag.glsl new file mode 100644 index 00000000000..901e56d2a35 --- /dev/null +++ b/shaders/GLSL/lava/lava_fog_light.frag.glsl @@ -0,0 +1,100 @@ +#version 330 +#extension GL_ARB_uniform_buffer_object : require +#extension GL_ARB_shading_language_420pack: require + +// This shader is Copyright (c) 2024 Beherith (mysterme@gmail.com) and licensed under the MIT License + +#line 20000 + +uniform float lavaHeight; +uniform float heatdistortx; +uniform float heatdistortz; + +uniform sampler2D mapDepths; +uniform sampler2D modelDepths; +uniform sampler2D lavaDistortion; +//uniform sampler2D mapNormals; +//uniform sampler2D modelNormals; + +in DataVS { + vec4 worldPos; + vec4 worldUV; + float inboundsness; + noperspective vec2 v_screenUV; +}; + +//__ENGINEUNIFORMBUFFERDEFS__ +//__DEFINES__ + +vec2 inverseMapSize = 1.0 / mapSize.xy; + +out vec4 fragColor; + +#line 22000 +void main() { + + vec4 camPos = cameraViewInv[3]; + + // We shift the distortion texture camera-upwards according to the uniforms that got passed in + vec2 camshift = vec2(heatdistortx, heatdistortz) * 0.01; + + //Get the fragment depth + // note that WE CANT GO LOWER THAN THE ACTUAL LAVA LEVEL! + + vec2 screenUV = clamp(v_screenUV, 1.0/(viewGeometry.xy), 1.0 - 1.0/ (viewGeometry.xy)); + + // Sample the depth buffers, and choose whichever is closer to the screen + float mapdepth = texture(mapDepths, screenUV).x; + float modeldepth = texture(modelDepths, screenUV).x; + mapdepth = min(mapdepth, modeldepth); + + // the W weight factor here is incorrect, as it comes from the depth buffers, and not the fragments own depth. + + // Convert to normalized device coordinates, and calculate inverse view projection + vec4 mapWorldPos = vec4( vec3(screenUV.xy * 2.0 - 1.0, mapdepth), 1.0); + mapWorldPos = cameraViewProjInv * mapWorldPos; + mapWorldPos.xyz = mapWorldPos.xyz/ mapWorldPos.w; // YAAAY this works! + float trueFragmentHeight = mapWorldPos.y; + + float fogAboveLava = 1.0; + + // clip mapWorldPos according to true lava height + if (mapWorldPos.y< lavaHeight - FOGHEIGHTABOVELAVA - HEIGHTOFFSET) { + // we need to make a vector from cam to fogplane position + vec3 camtofogplane = mapWorldPos.xyz - camPos.xyz; + + // and scale it to make it + camtofogplane = FOGHEIGHTABOVELAVA * camtofogplane /abs(camtofogplane.y); + mapWorldPos.xyz = worldPos.xyz + camtofogplane; + fogAboveLava = FOGABOVELAVA; + } + + // Calculate how long the vector from top of foglightplane to lava or world pos actually is + float actualfogdepth = length(mapWorldPos.xyz - worldPos.xyz) ; + float fogAmount = 1.0 - exp2(- FOGFACTOR * FOGFACTOR * actualfogdepth * 0.5); + fogAmount *= fogAboveLava; + + // sample the distortiontexture according to camera shift and scale it down + vec4 distortionTexture = texture(lavaDistortion, (worldUV.xy * 22.0 + camshift)) ; + float fogdistort = (FOGLIGHTDISTORTION + distortionTexture.x + distortionTexture.y)/ FOGLIGHTDISTORTION ; + + + // apply some distortion to the fog + fogAmount *= fogdistort; + + + // lets add some extra brigtness near the coasts, by finding the distance of the lavaplane to the coast + float disttocoast = abs(trueFragmentHeight- (lavaHeight - FOGHEIGHTABOVELAVA - HEIGHTOFFSET)); + + float extralightcoast = clamp(1.0 - disttocoast * (1.0 / COASTWIDTH), 0.0, 1.0); + extralightcoast = pow(extralightcoast, 3.0) * EXTRALIGHTCOAST; + + fogAmount += extralightcoast; + + fragColor.rgb = FOGCOLOR; + fragColor.a = fogAmount; + + // fade out the foglightplane if it is far out of bounds + fragColor.a *= clamp( inboundsness * 2.0 +2.0, 0.0, 1.0); + SWIZZLECOLORS +} diff --git a/shaders/GLSL/lava/lava_fog_light.vert.glsl b/shaders/GLSL/lava/lava_fog_light.vert.glsl new file mode 100644 index 00000000000..168bc3d0fbd --- /dev/null +++ b/shaders/GLSL/lava/lava_fog_light.vert.glsl @@ -0,0 +1,56 @@ +#version 420 +#extension GL_ARB_uniform_buffer_object : require +#extension GL_ARB_shader_storage_buffer_object : require +#extension GL_ARB_shading_language_420pack: require + +// This shader is Copyright (c) 2024 Beherith (mysterme@gmail.com) and licensed under the MIT License + +#line 10000 +layout (location = 0) in vec2 planePos; + +uniform float lavaHeight; + +out DataVS { + vec4 worldPos; + vec4 worldUV; + float inboundsness; + noperspective vec2 v_screenUV; +}; +//__DEFINES__ +//__ENGINEUNIFORMBUFFERDEFS__ + +#line 11000 + +#define SNORM2NORM(value) (value * 0.5 + 0.5) + +vec2 inverseMapSize = 1.0 / mapSize.xy; + +float rand(vec2 co){ // a pretty crappy random function + return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453); +} + +void main() { + // mapSize.xy is the actual map size, + //place the vertices into the world: + worldPos.y = lavaHeight; + worldPos.w = 1.0; + worldPos.xz = (1.5 * planePos +0.5) * mapSize.xy; + + // pass the world-space UVs out + float mapratio = mapSize.y / mapSize.x; + worldUV.xy = (1.5 * planePos +0.5); + worldUV.y *= mapratio; + + float gametime = (timeInfo.x + timeInfo.w) * 0.006666; + + vec4 randpervertex = vec4(rand(worldPos.xz), rand(worldPos.xz * vec2(17.876234, 9.283)), rand(worldPos.xz + gametime + 2.0), rand(worldPos.xz + gametime + 3.0)); + worldUV.zw = sin(randpervertex.xy + gametime * (0.5 + randpervertex.xy)); + + // -- MAP OUT OF BOUNDS + vec2 mymin = min(worldPos.xz, mapSize.xy - worldPos.xz) * inverseMapSize; + inboundsness = min(mymin.x, mymin.y); + + // Assign world position: + gl_Position = cameraViewProj * worldPos; + v_screenUV = SNORM2NORM(gl_Position.xy / gl_Position.w); +}