Skip to content

Commit

Permalink
Lamp Bloom, Exposure and Glare (#24534)
Browse files Browse the repository at this point in the history
* Light Update

* Not failing tests I hope

* Whitespace Removal

* Tweaking here and there

* Merge Conflict Fix

* Rebuild TGUI Bundle to Fix Merge Conflict

* Settings are now in "Game Preferences" too

* ColorMatrix formatting and removal of unused procs

* A little mistake on matrices

* A little mistake x2 (last I hope)

* Moving Glare under every other effect, tweaking values, playing with blending

* Update TGUI Bundle for Merge Conflict

* Apply suggestions from code reviews

* Fuck it, it just works

* No tabs cool

* Remove unused

* Am I retarded

* We better return

* Whitespace we need

* oh

* New SQL update version

* Missing comma fix and recompiled tgui.bundle

* Updating SQL version in misc_defines and config

* Remove datum in holder

* BloomEdit empty lines removal

* No more unneeded functions calls

* Tgui.bundle rebuild

* SQL Changes

* SQL Version = 56 now

* Documentation and some formatting

* tgui.bundle.js rebuild

* Remove unused layers and variables

* Allow cameras to render backdrops

* Possible runtime issue fix

* Remove "baked" bloom from the lamps

* Revert the "remove". Make it low on alpha channel

* Shuttle rotation light update fix

* We don't need this

* Possible runtime issue fix x2

* tgui.bundle.js update

* tgui.bundle.js update

* tgui.bundle.js update

* Revert config.toml changes

* Revert the revertion of config.toml changes

* Bring that config changes back!

* Entry added

* tgui.bundle.js update

* Prettier possible fix (?)

* Runtime fix (and broken tubes now have light after reinstalling them)

* config update

---------

Co-authored-by: Mikhail Dzianishchyts <[email protected]>
  • Loading branch information
MrRomainzZ and m-dzianishchyts authored Jul 5, 2024
1 parent 97eb823 commit e386cfd
Show file tree
Hide file tree
Showing 28 changed files with 776 additions and 56 deletions.
55 changes: 31 additions & 24 deletions code/__DEFINES/layers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -110,37 +110,44 @@
#define LIGHTING_PLANE 15
#define LIGHTING_LAYER 15

#define RAD_TEXT_LAYER 15.1
#define LIGHTING_LAMPS_GLARE 16 // Light glare (optional setting)
#define LIGHTING_EXPOSURE_PLANE 17 // Light sources "cones"
#define LIGHTING_LAMPS_SELFGLOW 18 // Light sources glow (lamps, doors overlay, etc.)
#define LIGHTING_LAMPS_PLANE 19 // Light sources themselves (lamps, screens, etc.)

#define ABOVE_LIGHTING_PLANE 16
#define ABOVE_LIGHTING_LAYER 16
#define LIGHTING_LAMPS_RENDER_TARGET "*LIGHTING_LAMPS_RENDER_TARGET"

#define FLOOR_OPENSPACE_PLANE 17
#define OPENSPACE_LAYER 17
#define RAD_TEXT_LAYER 19.1

#define BYOND_LIGHTING_PLANE 18
#define BYOND_LIGHTING_LAYER 18
#define ABOVE_LIGHTING_PLANE 20
#define ABOVE_LIGHTING_LAYER 20

#define CAMERA_STATIC_PLANE 19
#define CAMERA_STATIC_LAYER 19
#define FLOOR_OPENSPACE_PLANE 21
#define OPENSPACE_LAYER 21

#define BYOND_LIGHTING_PLANE 22
#define BYOND_LIGHTING_LAYER 22

#define CAMERA_STATIC_PLANE 23
#define CAMERA_STATIC_LAYER 23

//HUD layer defines

#define FULLSCREEN_PLANE 20
#define FLASH_LAYER 20
#define FULLSCREEN_LAYER 20.1
#define UI_DAMAGE_LAYER 20.2
#define BLIND_LAYER 20.3
#define CRIT_LAYER 20.4
#define CURSE_LAYER 20.5

#define HUD_PLANE 21
#define HUD_LAYER 21
#define ABOVE_HUD_PLANE 22
#define ABOVE_HUD_LAYER 22

#define SPLASHSCREEN_LAYER 23
#define SPLASHSCREEN_PLANE 23
#define FULLSCREEN_PLANE 24
#define FLASH_LAYER 24
#define FULLSCREEN_LAYER 24.1
#define UI_DAMAGE_LAYER 24.2
#define BLIND_LAYER 24.3
#define CRIT_LAYER 24.4
#define CURSE_LAYER 24.5

#define HUD_PLANE 25
#define HUD_LAYER 25
#define ABOVE_HUD_PLANE 26
#define ABOVE_HUD_LAYER 26

#define SPLASHSCREEN_LAYER 27
#define SPLASHSCREEN_PLANE 27

#define HUD_PLANE_BUILDMODE 30

Expand Down
18 changes: 16 additions & 2 deletions code/__DEFINES/preferences_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

#define SOUND_DEFAULT (SOUND_ADMINHELP|SOUND_MIDI|SOUND_AMBIENCE|SOUND_LOBBY|SOUND_HEARTBEAT|SOUND_BUZZ|SOUND_INSTRUMENTS|SOUND_MENTORHELP|SOUND_DISCO|SOUND_AI_VOICE|SOUND_PRAYERNOTIFY)

#define LIGHT_NEW_LIGHTING (1<<0)
#define LIGHT_EXPOSURE (1<<1)
#define LIGHT_GLARE (1<<2)

#define LIGHT_DEFAULT (LIGHT_NEW_LIGHTING|LIGHT_EXPOSURE|LIGHT_GLARE)

#define PREFTOGGLE_CHAT_OOC (1<<0)
#define PREFTOGGLE_CHAT_DEAD (1<<1)
#define PREFTOGGLE_CHAT_GHOSTEARS (1<<2)
Expand Down Expand Up @@ -92,10 +98,12 @@
#define PREFTOGGLE_SPECIAL 0
/// Interacts with the sound bitflag
#define PREFTOGGLE_SOUND 1
/// Interacts with the light bitflag
#define PREFTOGGLE_LIGHT 2
/// Interacts with the toggles bitflag
#define PREFTOGGLE_TOGGLE1 2
#define PREFTOGGLE_TOGGLE1 3
/// Interacts with the toggles2 bitflag
#define PREFTOGGLE_TOGGLE2 3
#define PREFTOGGLE_TOGGLE2 4


// Admin attack logs filter system, see /proc/add_attack_logs and /proc/msg_admin_attack
Expand All @@ -121,6 +129,12 @@

#define EXP_DEPT_TYPE_LIST list(EXP_TYPE_SUPPLY, EXP_TYPE_SERVICE, EXP_TYPE_MEDICAL, EXP_TYPE_ENGINEERING, EXP_TYPE_SCIENCE, EXP_TYPE_SECURITY, EXP_TYPE_COMMAND, EXP_TYPE_SILICON, EXP_TYPE_SPECIAL, EXP_TYPE_GHOST)

// Defines for the glow level preference for the lighting.
#define GLOW_HIGH 0
#define GLOW_MED 1 // Default.
#define GLOW_LOW 2
#define GLOW_DISABLE 3

// Defines just for parallax because its levels make storing it in the regular prefs a pain in the ass
// These dont need to be bitflags because there isnt going to be more than one at a time of these active
// But its gonna piss off my OCD if it isnt bitflags, so deal with it, -affected
Expand Down
10 changes: 10 additions & 0 deletions code/__HELPERS/filters.dm
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,13 @@ GLOBAL_LIST_INIT(master_filter_info, list(
/atom/proc/ray_filter_helper(_priority = 1, _size = 40, _color = "#FFFFFF", _factor = 6, _density = 20, _y = 0)
add_filter(name = "ray", priority = _priority, params = list(type = "rays", size = _size, color = _color , factor = _factor, density = _density, y = _y))

/proc/bloom_filter(threshold, size, offset, alpha)
. = list("type" = "bloom")
if(!isnull(threshold))
.["threshold"] = threshold
if(!isnull(size))
.["size"] = size
if(!isnull(offset))
.["offset"] = offset
if(!isnull(alpha))
.["alpha"] = alpha
2 changes: 1 addition & 1 deletion code/__HELPERS/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
for(var/path in subtypesof(/datum/preference_toggle))
var/datum/preference_toggle/pref_toggle = path
if(initial(pref_toggle.name))
GLOB.preference_toggles += new path()
GLOB.preference_toggles[path] = new path()

for(var/path in subtypesof(/datum/objective))
var/datum/objective/O = path
Expand Down
113 changes: 113 additions & 0 deletions code/__HELPERS/matrices.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Brightness (Luminance) of RGB on grayscale. Used for saturation matrix
#define LUM_R 0.3086 // or 0.2125
#define LUM_G 0.6094 // or 0.7154
#define LUM_B 0.0820 // or 0.0721

/matrix/proc/TurnTo(old_angle, new_angle)
. = new_angle - old_angle
Turn(.) //BYOND handles cases such as -270, 360, 540 etc. DOES NOT HANDLE 180 TURNS WELL, THEY TWEEN AND LOOK LIKE SHIT
Expand Down Expand Up @@ -63,3 +68,111 @@
//The Y pixel offset of this matrix
/matrix/proc/get_y_shift()
. = f

/// A color matrix allows us to set the color of an atom in a list form, thus allowing us to change color in more flexible ways. For example, we can set the brightness and contrast of the bloom and exposure of lamps
/datum/color_matrix
var/list/matrix

/// Value can be color as text (e.g. "#735184") that will set matrix to be the same color / number that will set the saturation of matrix / the color list itself, contrast as number, brightness as number
/datum/color_matrix/New(value, contrast = 1, brightness = null)
..()
if(istext(value))
set_color(value, contrast, brightness)
else if(isnum(value))
set_saturation(value, contrast, brightness)
else
matrix = value

/datum/color_matrix/proc/reset()
matrix = list(1, 0, 0,
0, 1, 0,
0, 0, 1)

/datum/color_matrix/proc/get(contrast = 1)
var/list/mat = matrix
mat = mat.Copy()

for(var/i = 1 to min(length(mat), 12))
mat[i] *= contrast
return mat

/datum/color_matrix/proc/set_saturation(saturation, contrast = 1, brightness = null)
var/r_adjustment = (1 - saturation) * LUM_R
var/g_adjustment = (1 - saturation) * LUM_G
var/b_adjustment = (1 - saturation) * LUM_B

matrix = list(contrast * (r_adjustment + saturation), contrast * (r_adjustment), contrast * (r_adjustment),
contrast * (g_adjustment), contrast * (g_adjustment + saturation), contrast * (g_adjustment),
contrast * (b_adjustment), contrast * (b_adjustment), contrast * (b_adjustment + saturation))
set_brightness(brightness)

/datum/color_matrix/proc/set_brightness(brightness)
if(isnull(brightness))
return

if(!matrix)
reset()

var/matrix_length = length(matrix)

// Here we have CCM matrix of type:
// | rr rg rb |
// | gr gg gb |
// | br bg bb |
// with no brightness row, just append it.
if(matrix_length == 9)
matrix += list(brightness, brightness, brightness)
return

// Here we have CCM matrix of type:
// | rr rg rb ra |
// | gr gg gb ga |
// | br bg bb ba |
// | ar ag ab aa |
// with no brightness row, just append it.
if(matrix_length == 16)
matrix += list(brightness, brightness, brightness, 0)
return

// We already have brightness row, just override.
if(matrix_length == 12)
for(var/i = matrix_length to matrix_length - 3 step -1)
matrix[i] = brightness
return

// Just brightness matrix, override.
if(matrix_length == 3)
for(var/i = 1 to matrix_length)
matrix[i] = brightness
return

CRASH("Couldn't figure out how to apply brightness to a matrix of length: [matrix_length]")

/// Handles values from 00 to FF.
/datum/color_matrix/proc/hex2value(hex)
var/const/radix = 16
var/num1 = text2num(hex[1], radix)
var/num2 = text2num(hex[2], radix)
if(!isnum(num1) || !isnum(num2))
CRASH("Invalid hex value: [hex]")

return num1 * radix + num2

/datum/color_matrix/proc/set_color(color_hex, contrast = 1, brightness = null)
var/rr = hex2value(copytext(color_hex, 2, 4)) / 255
var/gg = hex2value(copytext(color_hex, 4, 6)) / 255
var/bb = hex2value(copytext(color_hex, 6, 8)) / 255

rr = round(rr * 1000) / 1000 * contrast
gg = round(gg * 1000) / 1000 * contrast
bb = round(bb * 1000) / 1000 * contrast

matrix = list(rr, gg, bb,
rr, gg, bb,
rr, gg, bb)

set_brightness(brightness)

#undef LUM_R
#undef LUM_G
#undef LUM_B
79 changes: 79 additions & 0 deletions code/_onclick/hud/plane_master.dm
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,82 @@
plane = SMOKE_PLANE
appearance_flags = PLANE_MASTER
blend_mode = BLEND_OVERLAY

/atom/movable/screen/plane_master/lamps
name = "lamps plane master"
plane = LIGHTING_LAMPS_PLANE
blend_mode = BLEND_OVERLAY
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
render_target = LIGHTING_LAMPS_RENDER_TARGET

/atom/movable/screen/plane_master/exposure
name = "exposure plane master"
plane = LIGHTING_EXPOSURE_PLANE
appearance_flags = parent_type::appearance_flags | PIXEL_SCALE //should use client color
blend_mode = BLEND_ADD
mouse_opacity = MOUSE_OPACITY_TRANSPARENT

/atom/movable/screen/plane_master/exposure/backdrop(mob/mymob)
remove_filter("blur_exposure")
if(!istype(mymob) || !(mymob?.client?.prefs?.light & LIGHT_NEW_LIGHTING))
return
var/enabled = mymob?.client?.prefs?.light & LIGHT_EXPOSURE

if(enabled)
alpha = 255
add_filter("blur_exposure", 1, gauss_blur_filter(size = 20)) // by refs such blur is heavy, but tests were okay and this allow us more flexibility with setup. Possible point for improvements
else
alpha = 0

/atom/movable/screen/plane_master/lamps_selfglow
name = "lamps selfglow plane master"
plane = LIGHTING_LAMPS_SELFGLOW
appearance_flags = PLANE_MASTER //should use client color
blend_mode = BLEND_ADD
mouse_opacity = MOUSE_OPACITY_TRANSPARENT

/atom/movable/screen/plane_master/lamps_selfglow/backdrop(mob/mymob)
remove_filter("add_lamps_to_selfglow")
remove_filter("lamps_selfglow_bloom")

if(!istype(mymob) || !(mymob?.client?.prefs?.light & LIGHT_NEW_LIGHTING))
return
var/level = mymob?.client?.prefs?.glowlevel

if(isnull(level))
return
var/bloomsize = 0
var/bloomoffset = 0
switch(level)
if(GLOW_LOW)
bloomsize = 2
bloomoffset = 1
if(GLOW_MED)
bloomsize = 3
bloomoffset = 2
if(GLOW_HIGH)
bloomsize = 5
bloomoffset = 3
else
return

add_filter("add_lamps_to_selfglow", 1, layering_filter(render_source = LIGHTING_LAMPS_RENDER_TARGET, blend_mode = BLEND_OVERLAY))
add_filter("lamps_selfglow_bloom", 1, bloom_filter(threshold = "#777777", size = bloomsize, offset = bloomoffset, alpha = 80))

/atom/movable/screen/plane_master/lamps_glare
name = "lamps glare plane master"
plane = LIGHTING_LAMPS_GLARE
mouse_opacity = MOUSE_OPACITY_TRANSPARENT

/atom/movable/screen/plane_master/lamps_glare/backdrop(mob/mymob)
remove_filter("add_lamps_to_glare")
remove_filter("lamps_glare")

if(!istype(mymob) || !(mymob?.client?.prefs?.light & LIGHT_NEW_LIGHTING))
return

var/enabled = mymob?.client?.prefs?.light & LIGHT_GLARE

if(enabled)
add_filter("add_lamps_to_glare", 1, layering_filter(render_source = LIGHTING_LAMPS_RENDER_TARGET, blend_mode = BLEND_ADD))
add_filter("lamps_glare", 1, radial_blur_filter(size = 0.035))
12 changes: 11 additions & 1 deletion code/_onclick/hud/plane_master_controller.dm
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,14 @@

/atom/movable/plane_master_controller/game
name = PLANE_MASTERS_GAME
controlled_planes = list(FLOOR_PLANE, GAME_PLANE, LIGHTING_PLANE, PLANE_SPACE_PARALLAX, PLANE_SPACE)
controlled_planes = list(
FLOOR_PLANE,
GAME_PLANE,
LIGHTING_PLANE,
PLANE_SPACE_PARALLAX,
PLANE_SPACE,
LIGHTING_EXPOSURE_PLANE,
LIGHTING_LAMPS_SELFGLOW,
LIGHTING_LAMPS_PLANE,
LIGHTING_LAMPS_GLARE
)
4 changes: 4 additions & 0 deletions code/controllers/configuration/configuration_core.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ GLOBAL_DATUM_INIT(configuration, /datum/server_configuration, new())
var/datum/configuration_section/gamemode_configuration/gamemode
/// Holder for the general configuration datum
var/datum/configuration_section/general_configuration/general
/// Holder for the lighting effects configuration datum
var/datum/configuration_section/lighting_effects_configuration/lighting_effects
/// Holder for the IPIntel configuration datum
var/datum/configuration_section/ipintel_configuration/ipintel
/// Holder for the job configuration datum
Expand Down Expand Up @@ -82,6 +84,7 @@ GLOBAL_DATUM_INIT(configuration, /datum/server_configuration, new())
event = new()
gamemode = new()
general = new()
lighting_effects = new()
ipintel = new()
jobs = new()
logging = new()
Expand Down Expand Up @@ -120,6 +123,7 @@ GLOBAL_DATUM_INIT(configuration, /datum/server_configuration, new())
safe_load(event, "event_configuration")
safe_load(gamemode, "gamemode_configuration")
safe_load(general, "general_configuration")
safe_load(lighting_effects, "lighting_effects_configuration")
safe_load(ipintel, "ipintel_configuration")
safe_load(jobs, "job_configuration")
safe_load(logging, "logging_configuration")
Expand Down
Loading

0 comments on commit e386cfd

Please sign in to comment.