setShaderConsts
Definition
-- @/lua/ge/client/postFx/dof.lua:452
dOFPostEffectCallbacks.setShaderConsts = function()
local dofPostEffect = scenetree.findObject("DOFPostEffect")
if not dofPostEffect or not dofPostEffect.focalDist then
return
end
if dofPostEffect.autoFocusEnabled == true then
-- log('I','dof', ' setShaderConsts dofPostEffect = '..dumps(dofPostEffect))
-- log('I','dof', ' dof = '..dumps(dof))
autoFocus(dofPostEffect)
end
local farDist = tonumber(TorqueScriptLua.getVar("$Param::FarDist"))
local fd = dofPostEffect.focalDist / farDist
-- rangeNear is done in two phases, so that it can be clamped with rangeFar
local rangeNearTemp = lerp(dofPostEffect.minRange, dofPostEffect.maxRange, fd) / farDist * 0.5
local rangeFar = lerp(dofPostEffect.maxRange, dofPostEffect.minRange, fd) / farDist * 0.5
local rangeNear = clamp(rangeNearTemp, 0, rangeFar)
-- We work in "depth" space rather than real-world units for the
-- rest of this method...
-- Given the focal distance and the range around it we want in focus
-- we can determine the near-end-distance and far-start-distance
-- Original code was broken, so instead we re-use fsd
-- %ned = getMax( %fd - %range, 0.0 );
local ned = math.min(fd + rangeNear, 1.0)
local fsd = math.min(fd + rangeFar, 1.0)
-- nearSlope
local nsl = dofPostEffect.nearSlope
-- Given slope of near blur equation and the near end dist and amount (x2,y2)
-- solve for the y-intercept
-- y = mx + b
-- so...
-- y - mx = b
local b = 0.0 - nsl * ned
local eqNear = string.format("%f %f 0.0", nsl, b)
-- Do the same for the far blur equation...
local fsl = dofPostEffect.farSlope
b = 0.0 - fsl * fsd
local eqFar = string.format("%f %f 1.0", fsl, b)
-- Exposed the variables to the shader
local dofFinalPFX = scenetree.findObject("DOFFinalPFX")
if dofFinalPFX then
dofFinalPFX:setShaderConst("$dofEqWorld", eqNear)
dofFinalPFX:setShaderConst("$dofEqFar", eqFar)
dofFinalPFX:setShaderConst("$maxWorldCoC", dofPostEffect.nearBlurMax)
dofFinalPFX:setShaderConst("$maxFarCoC", dofPostEffect.farBlurMax)
dofFinalPFX:setShaderConst("$dofLerpScale", dofPostEffect.lerpScale)
dofFinalPFX:setShaderConst("$dofLerpBias", dofPostEffect.lerpBias)
dofFinalPFX:setShaderConst("$isDebugMode", dofPostEffect.debugModeEnabled and "1" or "0") -- send "1" for true and "0" for false
end
end
Callers