Skip to content

Commit

Permalink
Adds Bloom (#10230)
Browse files Browse the repository at this point in the history
* Adds bloom

* Lighting cleanup and reduce bloom intensity

* Remove some unused DEFINEs

* Tweak bloom and revert lighting changes

* SM Effects

* Fire power increases
  • Loading branch information
itsmeow authored Dec 10, 2023
1 parent 48cdd6c commit 549a8bd
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 7 deletions.
1 change: 1 addition & 0 deletions beestation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -2304,6 +2304,7 @@
#include "code\modules\client\preferences\entries\player\admin.dm"
#include "code\modules\client\preferences\entries\player\ambient_occlusion.dm"
#include "code\modules\client\preferences\entries\player\auto_fit_viewport.dm"
#include "code\modules\client\preferences\entries\player\bloom.dm"
#include "code\modules\client\preferences\entries\player\buttons_locked.dm"
#include "code\modules\client\preferences\entries\player\chat.dm"
#include "code\modules\client\preferences\entries\player\crew_objectives.dm"
Expand Down
1 change: 1 addition & 0 deletions code/__DEFINES/layers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
//---------- LIGHTING -------------
///Normal 1 per turf dynamic lighting objects
#define LIGHTING_PLANE 100
#define LIGHTING_PLANE_ADDITIVE 101

/// The plane for managing the global starlight effect
#define STARLIGHT_PLANE 105
Expand Down
9 changes: 4 additions & 5 deletions code/__DEFINES/lighting.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@
///This light doesn't affect turf's lumcount calculations. Set to 1<<15 to ignore conflicts
#define LIGHT_NO_LUMCOUNT (1<<15)

//Bay lighting engine shit, not in /code/modules/lighting because BYOND is being shit about it
#define LIGHTING_INTERVAL 5 // frequency, in 1/10ths of a second, of the lighting process

#define MINIMUM_USEFUL_LIGHT_RANGE 1.4

#define LIGHTING_FALLOFF 1 //! type of falloff to use for lighting; 1 for circular, 2 for square
#define LIGHTING_LAMBERTIAN 0 //! use lambertian shading for light sources
#define LIGHTING_HEIGHT 1 //! height off the ground of light sources on the pseudo-z-axis, you should probably leave this alone
#define LIGHTING_ROUND_VALUE (1 / 64) //! Value used to round lumcounts, values smaller than 1/129 don't matter (if they do, thanks sinking points), greater values will make lighting less precise, but in turn increase performance, VERY SLIGHTLY.

Expand Down Expand Up @@ -71,6 +66,10 @@

#define LIGHT_RANGE_FIRE 3 //! How many tiles standard fires glow.

#define ADDITIVE_LIGHTING_PLANE_ALPHA_MAX 255
#define ADDITIVE_LIGHTING_PLANE_ALPHA_NORMAL 128
#define ADDITIVE_LIGHTING_PLANE_ALPHA_INVISIBLE 0

#define LIGHTING_PLANE_ALPHA_VISIBLE 255
#define LIGHTING_PLANE_ALPHA_NV_TRAIT 250
#define LIGHTING_PLANE_ALPHA_MOSTLY_VISIBLE 192
Expand Down
6 changes: 6 additions & 0 deletions code/_onclick/hud/rendering/plane_master.dm
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
add_filter("emissives", 1, layering_filter(render_source = EMISSIVE_RENDER_TARGET, blend_mode = BLEND_ADD))
add_filter("lighting", 3, alpha_mask_filter(render_source = O_LIGHTING_VISUAL_RENDER_TARGET, flags = MASK_INVERSE))

/atom/movable/screen/plane_master/additive_lighting
name = "additive lighting plane master"
plane = LIGHTING_PLANE_ADDITIVE
blend_mode_override = BLEND_ADD
mouse_opacity = MOUSE_OPACITY_TRANSPARENT

/**
* Renders extremely blurred white stuff over space to give the effect of starlight lighting.
*/
Expand Down
1 change: 1 addition & 0 deletions code/_onclick/hud/rendering/plane_master_controller.dm
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@ INITIALIZE_IMMEDIATE(/atom/movable/plane_master_controller)
GHOST_PLANE,
POINT_PLANE,
LIGHTING_PLANE,
LIGHTING_PLANE_ADDITIVE,
)
8 changes: 7 additions & 1 deletion code/modules/atmospherics/environmental/LINDA_fire.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
blend_mode = BLEND_ADD
light_system = MOVABLE_LIGHT
light_range = LIGHT_RANGE_FIRE
light_power = 1
// increase power for more bloom
light_power = 4
light_color = LIGHT_COLOR_FIRE

var/volume = 125
Expand Down Expand Up @@ -112,18 +113,22 @@
heat_b = LERP(heat_b,255,normal_amt)
heat_a -= gauss_lerp(temperature, -5000, 5000) * 128
greyscale_fire -= normal_amt
light_power = 4
if(temperature > 40000) //Past this temperature the fire will gradually turn a bright purple
var/purple_amt = temperature < LERP(40000,200000,0.5) ? gauss_lerp(temperature, 40000, 200000) : 1
heat_r = LERP(heat_r,255,purple_amt)
light_power = 5
if(temperature > 200000 && temperature < 500000) //Somewhere at this temperature nitryl happens.
var/sparkle_amt = gauss_lerp(temperature, 200000, 500000)
var/mutable_appearance/sparkle_overlay = mutable_appearance('icons/effects/effects.dmi', "shieldsparkles")
sparkle_overlay.blend_mode = BLEND_ADD
sparkle_overlay.alpha = sparkle_amt * 255
light_power = 6
add_overlay(sparkle_overlay)
if(temperature > 400000 && temperature < 1500000) //Lightning because very anime.
var/mutable_appearance/lightning_overlay = mutable_appearance(icon, "overcharged")
lightning_overlay.blend_mode = BLEND_ADD
light_power = 6
add_overlay(lightning_overlay)
if(temperature > 4500000) //This is where noblium happens. Some fusion-y effects.
var/fusion_amt = temperature < LERP(4500000,12000000,0.5) ? gauss_lerp(temperature, 4500000, 12000000) : 1
Expand All @@ -139,6 +144,7 @@
heat_b = LERP(heat_b,150,fusion_amt)
add_overlay(fusion_overlay)
add_overlay(rainbow_overlay)
light_power = 8

set_light_color(rgb(LERP(250, heat_r, greyscale_fire), LERP(160, heat_g, greyscale_fire), LERP(25, heat_b, greyscale_fire)))

Expand Down
12 changes: 12 additions & 0 deletions code/modules/client/preferences/entries/player/bloom.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/datum/preference/numeric/bloom
category = PREFERENCE_CATEGORY_GAME_PREFERENCES
db_key = "bloom_amount"
preference_type = PREFERENCE_PLAYER
minimum = 0
maximum = 100

/datum/preference/numeric/bloom/create_default_value()
return round((ADDITIVE_LIGHTING_PLANE_ALPHA_NORMAL / 255) * 100)

/datum/preference/numeric/bloom/apply_to_client(client/client, value)
client.mob?.update_sight()
2 changes: 1 addition & 1 deletion code/modules/client/preferences/preference_entry.dm
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ GLOBAL_LIST_INIT(preference_entries_by_key, init_preference_entries_by_key())
"step" = step,
)

/// A prefernece whose value is always TRUE or FALSE
/// A preference whose value is always TRUE or FALSE
/datum/preference/toggle
abstract_type = /datum/preference/toggle

Expand Down
20 changes: 20 additions & 0 deletions code/modules/lighting/lighting_corner.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
var/cache_r = LIGHTING_SOFT_THRESHOLD
var/cache_g = LIGHTING_SOFT_THRESHOLD
var/cache_b = LIGHTING_SOFT_THRESHOLD

//additive light values
var/add_r = 0
var/add_g = 0
var/add_b = 0
var/applying_additive = FALSE

///the maximum of sum_r, sum_g, and sum_b. if this is > 1 then the three cached color values are divided by this
var/largest_color_luminosity = 0

Expand Down Expand Up @@ -111,10 +118,23 @@
self_r += delta_r
self_g += delta_g
self_b += delta_b

UPDATE_SUM_LUM(r)
UPDATE_SUM_LUM(g)
UPDATE_SUM_LUM(b)

add_r = clamp((self_r - 1.3) * 0.25, 0, 0.22)
add_g = clamp((self_g - 1.3) * 0.25, 0, 0.22)
add_b = clamp((self_b - 1.3) * 0.25, 0, 0.22)

// Client-shredding, does not cull any additive overlays.
//applying_additive = add_r || add_g || add_b
// Cull additive overlays that would be below 0.03 alpha in any color.
applying_additive = max(add_r, add_g, add_b) > 0.03
// Cull additive overlays whose color alpha sum is lower than 0.03
//applying_additive = (add_r + add_g + add_b) > 0.03


#ifdef ZMIMIC_LIGHT_BLEED
var/turf/T
var/datum/lighting_corner/C
Expand Down
35 changes: 35 additions & 0 deletions code/modules/lighting/lighting_object.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

var/needs_update = FALSE
var/turf/myturf
var/mutable_appearance/additive_underlay

/atom/movable/lighting_object/Initialize(mapload)
. = ..()
Expand All @@ -24,6 +25,9 @@
myturf.lighting_object = src
myturf.luminosity = 0

additive_underlay = mutable_appearance(LIGHTING_ICON, "light", FLOAT_LAYER, LIGHTING_PLANE_ADDITIVE, 255, RESET_COLOR | RESET_ALPHA | RESET_TRANSFORM)
additive_underlay.blend_mode = BLEND_ADD

needs_update = TRUE
SSlighting.objects_queue += src

Expand All @@ -37,6 +41,7 @@
if (isturf(myturf))
myturf.lighting_object = null
myturf.luminosity = initial(myturf.luminosity)
myturf.underlays -= additive_underlay
myturf = null

return ..()
Expand Down Expand Up @@ -113,6 +118,36 @@
00, 00, 00, 01
)

if(cr.applying_additive || cg.applying_additive || cb.applying_additive || ca.applying_additive)
myturf.underlays -= additive_underlay
additive_underlay.icon_state = "light"
var/arr = cr.add_r
var/arb = cr.add_b
var/arg = cr.add_g

var/agr = cg.add_r
var/agb = cg.add_b
var/agg = cg.add_g

var/abr = cb.add_r
var/abb = cb.add_b
var/abg = cb.add_g

var/aarr = ca.add_r
var/aarb = ca.add_b
var/aarg = ca.add_g

additive_underlay.color = list(
arr, arg, arb, 00,
agr, agg, agb, 00,
abr, abg, abb, 00,
aarr, aarg, aarb, 00,
00, 00, 00, 01
)
myturf.underlays += additive_underlay
else
myturf.underlays -= additive_underlay

luminosity = set_luminosity

if (myturf.above)
Expand Down
6 changes: 6 additions & 0 deletions code/modules/mob/mob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,12 @@
var/atom/movable/screen/plane_master/lighting/L = hud_used.plane_masters["[LIGHTING_PLANE]"]
if (L)
L.alpha = lighting_alpha
var/atom/movable/screen/plane_master/additive_lighting/LA = hud_used.plane_masters["[LIGHTING_PLANE_ADDITIVE]"]
if(LA)
var/bloom = ADDITIVE_LIGHTING_PLANE_ALPHA_NORMAL
if(client?.prefs) //If this ever doesn't work for some reason add update_sight() to /mob/living/Login()
bloom = client.prefs.read_preference(/datum/preference/numeric/bloom) * (ADDITIVE_LIGHTING_PLANE_ALPHA_MAX / 100)
LA.alpha = lighting_alpha * (bloom / 255)

///Update the mouse pointer of the attached client in this mob
/mob/proc/update_mouse_pointer()
Expand Down
2 changes: 2 additions & 0 deletions code/modules/power/apc/apc_main.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
layer = ABOVE_WINDOW_LAYER
zmm_flags = ZMM_MANGLE_PLANES

light_power = 0.85



FASTDMM_PROP(\
Expand Down
18 changes: 18 additions & 0 deletions code/modules/power/supermatter/supermatter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ GLOBAL_DATUM(main_supermatter_engine, /obj/machinery/power/supermatter_crystal)
var/uid = 1
var/static/gl_uid = 1
light_range = 4
// this thing bright as hell (to increase bloom)
light_power = 5
light_color = "#ffe016"
resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | UNACIDABLE | ACID_PROOF | FREEZE_PROOF
flags_1 = PREVENT_CONTENTS_EXPLOSION_1
critical_machine = TRUE
Expand Down Expand Up @@ -291,26 +294,41 @@ GLOBAL_DATUM(main_supermatter_engine, /obj/machinery/power/supermatter_crystal)
distort.icon_state = "SM_base"
distort.pixel_x = -32
distort.pixel_y = -32
light_range = 4
light_power = 5
light_color = "#ffe016"
if(SUPERMATTER_NORMAL, SUPERMATTER_NOTIFY, SUPERMATTER_WARNING)
distort.icon = 'icons/effects/96x96.dmi'
distort.icon_state = "SM_base_active"
distort.pixel_x = -32
distort.pixel_y = -32
light_range = 4
light_power = 7
light_color = "#ffe016"
if(SUPERMATTER_DANGER)
distort.icon = 'icons/effects/160x160.dmi'
distort.icon_state = "SM_delam_1"
distort.pixel_x = -64
distort.pixel_y = -64
light_range = 5
light_power = 10
light_color = "#ffb516"
if(SUPERMATTER_EMERGENCY)
distort.icon = 'icons/effects/224x224.dmi'
distort.icon_state = "SM_delam_2"
distort.pixel_x = -96
distort.pixel_y = -96
light_range = 6
light_power = 10
light_color = "#ff9208"
if(SUPERMATTER_DELAMINATING)
distort.icon = 'icons/effects/288x288.dmi'
distort.icon_state = "SM_delam_3"
distort.pixel_x = -128
distort.pixel_y = -128
light_range = 7
light_power = 15
light_color = "#ff5006"
return distort

/obj/machinery/power/supermatter_crystal/proc/countdown()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { FeatureNumberInput, FeatureNumeric } from '../base';

export const bloom_amount: FeatureNumeric = {
name: 'Bloom Level',
category: 'GRAPHICS',
subcategory: 'Misc',
description:
'What percentage of bloom to show. Bloom is a lighting effect that gives bright lights a whiteout effect. Disabling it entirely may increase client performance, if needed.',
component: FeatureNumberInput,
};

0 comments on commit 549a8bd

Please sign in to comment.