mirror of
https://github.com/t-affeldt/lighting_monoids.git
synced 2025-04-25 14:00:28 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7ac833bb19 | ||
|
8108a5d585 | ||
|
a65f43bded | ||
|
f864b8ea7c |
@ -1,7 +1,7 @@
|
||||
The MIT License (MIT)
|
||||
=====================
|
||||
|
||||
Copyright © `2023` `Till Affeldt`
|
||||
Copyright © `2023 - 2024` `Till Affeldt`
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
|
@ -15,15 +15,17 @@ Each property of the lighting definition will be aggregated with the respective
|
||||
|
||||
Properties will be aggregated in different ways. Here is the full list:
|
||||
|
||||
- `saturation` will be __multiplied__
|
||||
- `shadows`
|
||||
- `intensity` will be __multiplied__
|
||||
- `exposure`
|
||||
- `luminance_min` will be __added__
|
||||
- `luminance_max` will be __added__
|
||||
- `speed_dark_bright` will be __multiplied__
|
||||
- `speed_bright_dark` will be __multiplied__
|
||||
- `center_weight_power` will be __multiplied__
|
||||
- `saturation` will be __multiplied__
|
||||
- `shadows`
|
||||
- `intensity` will be __multiplied__
|
||||
- `tint` values will be __maxed__
|
||||
- `volumetric_light` will be __maxed__
|
||||
|
||||
### Example
|
||||
|
||||
|
@ -11,7 +11,8 @@ local default_intensity = tonumber(minetest.settings:get("enable_shadows_default
|
||||
local intensity = tonumber(storage:get("intensity") or default_intensity)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
lighting_monoids.shadows:add_change(player, intensity, "enable_shadows:base_value")
|
||||
local lighting = { shadows = { intensity = intensity } }
|
||||
lighting_monoid:add_change(player, lighting, "enable_shadows:base_value")
|
||||
end)
|
||||
|
||||
minetest.override_chatcommand("shadow_intensity", {
|
||||
|
@ -1,13 +1,35 @@
|
||||
-- Hook into MTG weather mod for compatibility (requires PR #3020)
|
||||
if weather ~= nil and weather.on_update ~= nil then
|
||||
weather.on_update = function(player, overrides)
|
||||
if overrides == nil then
|
||||
return
|
||||
end
|
||||
if overrides.shadows then
|
||||
lighting_monoid:add_change(player, { shadows = overrides.shadows }, "weather:cloud_shadows")
|
||||
end
|
||||
overrides.lighting = nil
|
||||
return overrides
|
||||
end
|
||||
local CYCLE = 8
|
||||
local BASE_SHADOW = 0.33
|
||||
|
||||
-- weather API not supported, no patch possible
|
||||
if weather == nil or weather.get == nil then
|
||||
minetest.log("warning", "[Lighting_Monoid] 'weather' mod does not support patching via API. If you are playing Minetest Game, update to the latest version")
|
||||
return
|
||||
end
|
||||
|
||||
-- leave it to climate_api to disable
|
||||
if minetest.get_modpath("climate_api") then
|
||||
return
|
||||
end
|
||||
|
||||
-- prevent mod from triggering lighting updates itself
|
||||
local old_get = weather.get
|
||||
weather.get = function(player)
|
||||
local params = old_get(player)
|
||||
params.lighting = nil
|
||||
return params
|
||||
end
|
||||
|
||||
local function do_update()
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local params = old_get(player)
|
||||
local lighting = params.lighting
|
||||
if lighting ~= nil and lighting.shadows ~= nil and lighting.shadows.intensity ~= nil then
|
||||
-- normalize in relation to default intensity
|
||||
lighting.shadows.intensity = lighting.shadows.intensity / BASE_SHADOW
|
||||
end
|
||||
lighting_monoid:add_change(player, lighting, "weather:lighting")
|
||||
end
|
||||
minetest.after(CYCLE, do_update)
|
||||
end
|
||||
minetest.after(0, do_update)
|
47
init.lua
47
init.lua
@ -1,11 +1,14 @@
|
||||
local SET_BASE_SHADOW = minetest.settings:get_bool("lighting_monoids.set_base_shadow", true)
|
||||
local BASE_SHADOW_INTENSITY = tonumber(minetest.settings:get("lighting_monoids.base_shadow_intensity") or 0.33)
|
||||
|
||||
local MODPATH = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
local monoid_definition = {
|
||||
shadows = {
|
||||
intensity = "multiply_minmax",
|
||||
intensity = "multiply",
|
||||
},
|
||||
tint = {
|
||||
r = "max_255",
|
||||
g = "max_255",
|
||||
b = "max_255"
|
||||
},
|
||||
saturation = "multiply",
|
||||
exposure = {
|
||||
@ -15,16 +18,31 @@ local monoid_definition = {
|
||||
speed_dark_bright = "multiply",
|
||||
speed_bright_dark = "multiply",
|
||||
center_weight_power = "multiply"
|
||||
},
|
||||
volumetric_light = {
|
||||
strength = "max_1"
|
||||
}
|
||||
}
|
||||
|
||||
-- default values that don't reflect neutral operations
|
||||
-- neutral values
|
||||
local lighting_defaults = {
|
||||
shadows = {
|
||||
intensity = 1,
|
||||
},
|
||||
tint = {
|
||||
r = 0,
|
||||
g = 0,
|
||||
b = 0
|
||||
},
|
||||
saturation = 1,
|
||||
exposure = {
|
||||
luminance_min = -3,
|
||||
luminance_max = -3,
|
||||
speed_dark_bright = 1000,
|
||||
speed_bright_dark = 1000,
|
||||
},
|
||||
volumetric_light = {
|
||||
strength = 0
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,8 +56,12 @@ function methods.multiply(a, b)
|
||||
return a * b
|
||||
end
|
||||
|
||||
function methods.multiply_minmax(a, b)
|
||||
return math.max(math.min(a * b, 1), 0)
|
||||
function methods.max_1(a, b)
|
||||
return math.min(math.max(math.max(a, b), 0), 1)
|
||||
end
|
||||
|
||||
function methods.max_255(a, b)
|
||||
return math.min(math.max(math.max(a, b), 0), 255)
|
||||
end
|
||||
|
||||
-- combine tables using specified methods
|
||||
@ -69,7 +91,7 @@ lighting_monoid = player_monoids.make_monoid({
|
||||
end,
|
||||
fold = function(values)
|
||||
local total = {}
|
||||
for _, val in ipairs(values) do
|
||||
for _, val in pairs(values) do
|
||||
total = combine(monoid_definition, total, val)
|
||||
end
|
||||
return total
|
||||
@ -78,20 +100,23 @@ lighting_monoid = player_monoids.make_monoid({
|
||||
if player.set_lighting ~= nil then
|
||||
-- incorporate default offsets
|
||||
value = combine(monoid_definition, lighting_defaults, value)
|
||||
-- restrict shadow intensity to valid range
|
||||
if value ~= nil and value.shadows ~= nil and value.shadows.intensity ~= nil then
|
||||
value.shadows.intensity = math.max(math.min(value.shadows.intensity, 1), 0)
|
||||
end
|
||||
player:set_lighting(value)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
if minetest.get_modpath("weather") then
|
||||
if minetest.get_modpath("weather") and minetest.settings:get_bool("enable_weather") ~= false then
|
||||
dofile(MODPATH .. DIR_DELIM .. "compatibility" .. DIR_DELIM .. "weather.lua")
|
||||
end
|
||||
|
||||
if minetest.get_modpath("enable_shadows") then
|
||||
dofile(MODPATH .. DIR_DELIM .. "compatibility" .. DIR_DELIM .. "enable_shadows.lua")
|
||||
|
||||
-- set base shadow
|
||||
elseif SET_BASE_SHADOW then
|
||||
else
|
||||
-- set base shadow
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local lighting = { shadows = { intensity = BASE_SHADOW_INTENSITY } }
|
||||
lighting_monoid:add_change(player, lighting, "lighting_monoid:base_shadow")
|
||||
|
@ -1,4 +1,2 @@
|
||||
# If enabled, lighting_monoids will assign a base value to the shadow intensity.
|
||||
lighting_monoids.set_base_shadow (Set base shadow) bool true
|
||||
# The base value that will be used when no other effect is active.
|
||||
lighting_monoids.base_shadow_intensity (Base shadow intensity) float 0.33 0 1
|
Loading…
x
Reference in New Issue
Block a user