View Issue Details

IDProjectCategoryView StatusLast Update
0009113New Feature RequestsGeneralpublic2017-06-18 20:56
Reporteralberto2345 Assigned To 
Status newResolutionopen 
Summary0009113: [Request] Add Intensity for lights

Changing lights intensity by a function and/or with createLight as an optional argument.


I'm sure this is possible right?

TagsNo tags attached.



2016-01-13 20:30

viewer   ~~0024323

Last edited: 2016-01-13 20:38

View 4 revisions

You can implement this easily in Lua, because the intensity of a light is proportional to its color brightness, so multiplying a bright color's RGB values with a coefficient in the range 0-1 is enough. I did this function as an example of a complete implementation of an extra intensity argument in the createLight function:

local intensityArgNumber = 13 -- The intensity extra argument position. Should be greater than 8
local _createLight = createLight
function createLight(...)
-- Last argument is our new intensity argument, if specified (it's optional)
local argTable, intensity = { ... }, #argTable < intensityArgNumber and 0 or tonumber(argTable[intensityArgNumber])
local isIntensityANumber = intensity ~= false
if isIntensityANumber and intensity >= 0 and intensity <= 1 then
-- The extra argument looks nice. Check RGB values too
local r, g, b = argTable[6], argTable[7], argTable[8]
if (r ~= nil and type(r) ~= "number") or (g ~= nil and type(g) ~= "number") or (b ~= nil and type(b) ~= "number") then
error("Bad argument 6, 7 and/or 8 @ createLight (RGB values or nothing expected, got anything else)")
-- Do the actual fancy thing
argTable[6], argTable[7], argTable[8] = (r or 255) intensity, (g or 0) intensity, (b or 0) * intensity
table.remove(argTable, intensityArgNumber) -- Take the fake argument out of consideration for the original function
return _createLight(unpack(argTable))
-- It doesn't look nice. Throw a descriptive error
error("Bad argument " .. intensityArgNumber .. " @ createLight (" .. (isIntensityANumber and "intensity is not in 0-1 range" or ("number expected, got " .. type(intensity))) .. ")")

Issue History

Date Modified Username Field Change