[FATALITY] Bloom

  • 20
  • 1
  • 12
1671229842712.png

Lua:
local path = "lua>tab b"
local wallcolor_reference = gui.add_checkbox("Wall Color",path)
local wallcolor_color_reference = gui.add_colorpicker(path..">wall color",true,render.color(255, 0, 0, 128))
local ppc = gui.get_config_item("visuals>misc>various>disable post-processing")
local stored = ppc:get_bool()
local bloom_reference = gui.add_slider("Bloom scale", path, 0, 500, 1)
local model_ambient_min_reference = gui.add_slider("Minimum model brightness", path, 0, 1000, 1)

local max_val = 1

local bloom_default
local bloom_prev, model_ambient_min_prev, wallcolor_prev

local function reset_bloom(tone_map_controller)
    if bloom_default == 0 then
        tone_map_controller:set_prop("m_bUseCustomBloomScale", 0,false)
        tone_map_controller:set_prop("m_flCustomBloomScale", 0,0)
    else
        tone_map_controller:set_prop("m_bUseCustomBloomScale", 0, false)
        tone_map_controller:set_prop("m_flCustomBloomScale", 0,bloom_default)
    end
end

local function entity_get_all(class)
    local ret = {}
    entities.for_each(function(entity)
        if entity:get_class() == class then
            table.insert(ret,entity)
        end
    end)
    return ret
end
ppc:set_bool(false)
function on_paint()
    local wallcolor = (wallcolor_reference):get_bool()
    if wallcolor or wallcolor_prev then
        if wallcolor then
            local c = (wallcolor_color_reference):get_color()
            local r, g, b, a = c.r,c.g,c.b,c.a
            r, g, b = r/255, g/255, b/255
            local a_temp = a / 128 - 1
            local r_res, g_res, b_res
            if a_temp > 0 then
                local multiplier = 900^(a_temp) - 1
                a_temp = a_temp * multiplier
                r_res, g_res, b_res = r*a_temp, g*a_temp, b*a_temp
            else
                a_temp = a_temp * max_val
                r_res, g_res, b_res = (1-r)*a_temp, (1-g)*a_temp, (1-b)*a_temp
            end
            if cvar.mat_ambient_light_r:get_float() ~= r_res or cvar.mat_ambient_light_g:get_float() ~= g_res or cvar.mat_ambient_light_b:get_float() ~= b_res then
                cvar.mat_ambient_light_r:set_float(r_res)
                cvar.mat_ambient_light_g:set_float(g_res)
                cvar.mat_ambient_light_b:set_float(b_res)
            end
        else
            cvar.mat_ambient_light_r:set_float(0)
            cvar.mat_ambient_light_g:set_float(0)
            cvar.mat_ambient_light_b:set_float(0)
        end
    end
    wallcolor_prev = wallcolor

    local model_ambient_min = (model_ambient_min_reference):get_int()
    if model_ambient_min > 0 or (model_ambient_min_prev ~= nil and model_ambient_min_prev > 0) then
        if cvar.r_modelAmbientMin:get_float() ~= model_ambient_min*0.05 then
            cvar.r_modelAmbientMin:set_float(model_ambient_min*0.05)
        end
    end
    model_ambient_min_prev = model_ambient_min

    local bloom = (bloom_reference):get_int()
    if bloom ~= 0  or bloom_prev ~= 0 then
        local tone_map_controllers = entity_get_all("CEnvTonemapController")
        for i=1, #tone_map_controllers do
            local tone_map_controller = tone_map_controllers[i]
            if bloom ~= 0 then
                if bloom_default == nil then
                    if tone_map_controller:get_prop("m_bUseCustomBloomScale") == true then
                        bloom_default = tone_map_controller:get_prop("m_flCustomBloomScale")
                    else
                        bloom_default = 0
                    end
                end
                tone_map_controller:set_prop("m_bUseCustomBloomScale", 0, true)
                tone_map_controller:set_prop("m_flCustomBloomScale", 0, bloom*0.01)
            elseif bloom_prev ~= nil and bloom_prev ~= 0 and bloom_default ~= nil then
                reset_bloom(tone_map_controller)
            end
        end
    end
    bloom_prev = bloom
end
local timer = utils.new_timer(500, function()
    if info.server.map_name == nil then
        bloom_default = nil
    end
end)
timer:start()

function on_shutdown()
    local tone_map_controllers = entity_get_all("CEnvTonemapController")
    for i=1, #tone_map_controllers do
        local tone_map_controller = tone_map_controllers[i]
        if bloom_prev ~= 0 and bloom_default ~= nil then
            reset_bloom(tone_map_controller)
        end
    end
    cvar.mat_ambient_light_r:set_float(0)
    cvar.mat_ambient_light_g:set_float(0)
    cvar.mat_ambient_light_b:set_float(0)
    cvar.r_modelAmbientMin:set_float(0)
    ppc:set_bool(stored)
end
 

Вложения

  • bloom.lua
    4 KB · Просмотры: 76
Сверху Снизу